test_that("code_editor_themes returns character vector of themes", { themes <- code_editor_themes() expect_type(themes, "character") expect_true(length(themes) > 0) # Check for expected default themes expect_true("github-light" %in% themes) expect_true("github-dark" %in% themes) expect_true("vs-code-light" %in% themes) expect_true("vs-code-dark" %in% themes) }) test_that("input_code_editor() rejects invalid themes", { expect_snapshot(error = TRUE, { input_code_editor("test", theme_light = "invalid-theme") }) }) test_that("arg_match_language rejects invalid languages", { expect_snapshot(error = TRUE, { input_code_editor("test", language = "fortran") }) }) test_that("input_code_editor generates correct HTML structure", { editor <- input_code_editor( "test_editor", value = "SELECT * FROM table", language = "sql" ) # Check that dependencies are attached deps <- htmltools::findDependencies(editor) dep_names <- sapply(deps, function(d) d$name) expect_true("prism-code-editor" %in% dep_names) expect_true("bslib-code-editor" %in% dep_names) html <- as.character(editor) # Check for bslib-code-editor custom element tag expect_match(html, ' 0) # Check that all expected dependencies are present dep_names <- sapply(deps, function(d) d$name) expect_true("prism-code-editor" %in% dep_names) expect_true("bslib-code-editor" %in% dep_names) }) test_that("input_code_editor works with different languages", { languages <- c("sql", "python", "r", "javascript", "markup", "css", "json") for (lang in languages) { editor <- input_code_editor(paste0("editor_", lang), language = lang) html <- as.character(editor) expect_match(html, sprintf('language="%s"', lang)) } }) test_that("input_code_editor tab_size validates range", { # Valid tab sizes expect_silent(input_code_editor("test1", tab_size = 2)) expect_silent(input_code_editor("test2", tab_size = 4)) expect_silent(input_code_editor("test3", tab_size = 8)) expect_error(input_code_editor("test4", tab_size = 0)) }) test_that("input_code_editor warns when value has 1,000 or more lines", { # No warning for small values expect_silent(input_code_editor("test1", value = "line1\nline2\nline3")) # No warning for exactly 999 lines value_999 <- paste(rep("line", 999), collapse = "\n") expect_silent(input_code_editor("test2", value = value_999)) # Warning for exactly 1000 lines value_1000 <- paste(rep("line", 1000), collapse = "\n") expect_warning( input_code_editor("test3", value = value_1000), "Code editor value contains 1000 lines" ) expect_warning( input_code_editor("test3", value = value_1000), "performance issues" ) # Warning for more than 1000 lines value_2000 <- paste(rep("line", 2000), collapse = "\n") expect_warning( input_code_editor("test4", value = value_2000), "Code editor value contains 2000 lines" ) }) test_that("update_code_editor warns when value has 1,000 or more lines", { mock_session <- list(sendInputMessage = function(...) invisible()) # No warning for small values expect_silent(update_code_editor( "test1", value = "line1\nline2", session = mock_session )) # Warning for exactly 1000 lines value_1000 <- paste(rep("line", 1000), collapse = "\n") expect_warning( update_code_editor("test4", value = value_1000, session = mock_session), "Code editor value contains 1000 lines" ) # Warning for more than 1000 lines value_2000 <- paste(rep("line", 2000), collapse = "\n") expect_warning( update_code_editor("test4", value = value_1000, session = mock_session), "Code editor value contains 1000 lines" ) }) test_that("check_value_line_count handles edge cases", { # NULL value expect_silent(bslib:::check_value_line_count(NULL)) # Empty string expect_silent(bslib:::check_value_line_count("")) # Empty character vector expect_silent(bslib:::check_value_line_count(character(0))) # Single line expect_silent(bslib:::check_value_line_count("single line")) # Multiple lines below threshold value_100 <- paste(rep("line", 100), collapse = "\n") expect_silent(bslib:::check_value_line_count(value_100)) })