1# 2# test-prefs 3# 4# Copyright (C) 2021 by RStudio, PBC 5# 6# Unless you have received this program directly from RStudio pursuant 7# to the terms of a commercial license agreement with RStudio, then 8# this program is licensed to you under the terms of version 3 of the 9# GNU Affero General Public License. This program is distributed WITHOUT 10# ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 11# MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 12# AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details. 13# 14# 15 16context("prefs") 17 18test_that("preference values can be set", { 19 # create a new temporary value for the code completion pref 20 oldVal <- .rs.readUiPref("code_completion_delay") 21 newVal <- oldVal + 50L 22 23 # set it to a new value and ensure that it sticks 24 .rs.writeUiPref("code_completion_delay", newVal) 25 expect_equal(.rs.readUiPref("code_completion_delay"), newVal) 26 27 # restore the old value and ensure that it sticks 28 .rs.writeUiPref("code_completion_delay", oldVal) 29 expect_equal(.rs.readUiPref("code_completion_delay"), oldVal) 30}) 31 32test_that("default values for preferences are respected", { 33 oldVal <- .rs.readUiPref("num_spaces_for_tab") 34 35 # set it to a new value and ensure that it sticks 36 newVal <- oldVal + 2L 37 .rs.writeUiPref("num_spaces_for_tab", newVal) 38 expect_equal(.rs.readUiPref("num_spaces_for_tab"), newVal) 39 40 # remove the value entirely and ensure it falls back to the default (this presumes the default is 41 # 2, but we are unlikely to change the historical default of this pref!) 42 .rs.removePref("num_spaces_for_tab") 43 expect_equal(.rs.readUiPref("num_spaces_for_tab"), 2) 44 45 # restore the old value if it wasn't the default 46 if (oldVal != 2) { 47 .rs.writeUiPref("num_spaces_for_tab", oldVal) 48 } 49}) 50 51test_that("rstudio API prefs are separate from IDE prefs", { 52 # read an old value from the RStudio preference 53 oldVal <- .rs.api.readRStudioPreference("code_completion_delay") 54 newVal <- oldVal + 50L 55 56 # save the new value as a regular (non-RStudio) pref 57 .rs.api.writePreference("code_completion_delay", newVal) 58 59 # ensure that the new value was written correctly 60 prefVal <- .rs.api.readPreference("code_completion_delay") 61 expect_equal(prefVal, newVal) 62 63 # ensure that the original RStudio preference is untouched 64 prefVal <- .rs.api.readRStudioPreference("code_completion_delay") 65 expect_equal(prefVal, oldVal) 66}) 67