testthat::context("general ROCK tests") require(rock); ###----------------------------------------------------------------------------- ###----------------------------------------------------------------------------- ###----------------------------------------------------------------------------- testthat::test_that("reading a source with no ROCK stuff works properly", { examplePath <- file.path(system.file(package="rock"), 'extdata'); testres <- parse_source(file.path(examplePath, "lorum-ipsum.rock")); testthat::expect_s3_class(testres, "rock_parsedSource"); }); ###----------------------------------------------------------------------------- testthat::test_that("an inductive code tree is read correctly", { ### devtools::load_all(); examplePath <- file.path(system.file(package="rock"), 'extdata'); testres <- parse_source( file.path( examplePath, "longer-test.rock" #examplePath, "streams", "Source2_StreamA.rock" ), silent=TRUE ); testthat::expect_equal(testres$inductiveCodeTrees$codes$inductFather$inducChild3$label, "inducChild3"); }); ###----------------------------------------------------------------------------- testthat::test_that("example 2 is read correctly", { examplePath <- file.path(system.file(package="rock"), 'extdata'); testres <- rock::parse_source(file.path(examplePath, "example-2.rock"), silent=TRUE); testres_fragment <- testres$qdt[ , c('uids', 'utterances_clean', 'sectionBreak_paragraph_break_counter', 'caseId', 'childCode', 'grandChildCode', 'grandChildCode2', 'justAcode', 'region', 'age') ]; testthat::expect_equal(nrow(testres_fragment), 16); }); ###----------------------------------------------------------------------------- testthat::test_that("a code tree is printed correctly", { examplePath <- file.path(system.file(package="rock"), 'extdata'); testres <- parse_source(file.path(examplePath, "longer-test.rock"), silent=TRUE); testthat::expect_output(print(testres), "This source contained inductive coding trees."); testthat::expect_output(print(testres), "This source contained deductive coding trees."); }); ###----------------------------------------------------------------------------- testthat::test_that("an inductive code tree is read correctly using parse_sources()", { examplePath <- file.path(system.file(package="rock"), 'extdata'); testres <- parse_sources(path = examplePath, regex = "longer-test.rock", silent=TRUE); testthat::expect_equal(testres$inductiveCodeTrees$codes$inductFather$inducChild3$label, "inducChild3"); }); ###----------------------------------------------------------------------------- testthat::test_that("a single deductive code tree is read correctly", { examplePath <- file.path(system.file(package="rock"), 'extdata'); testres <- parse_source(file.path(examplePath, "second-test-file.rock")); testthat::expect_equal(testres$deductiveCodeTrees$parentCode1$someParent$childCode1$label, "childCode1"); }); ###----------------------------------------------------------------------------- testthat::test_that("Multiple sources are read correctly", { examplePath <- file.path(system.file(package="rock"), 'extdata'); rock::opts$set(warnForMultipleAesthetics = FALSE); testres <- parse_sources(examplePath, extension="rock", silent=TRUE); rock::opts$set(warnForMultipleAesthetics = TRUE); testthat::expect_equal(testres$deductiveCodeTrees$children$parentCode1$someParent$childCode2$label, "childCode2"); }); ###----------------------------------------------------------------------------- testthat::test_that("multiple sources without deductive code trees are read correctly (i.e. as NA)", { examplePath <- file.path(system.file(package="rock"), 'extdata'); testres <- parse_sources(examplePath, regex = "ipsum"); testthat::expect_true(identical(testres$deductiveCodeTrees, NA)); }); ###----------------------------------------------------------------------------- testthat::test_that("A deductive code tree is read correctly from multiple DCT files", { examplePath <- file.path(system.file(package="rock"), 'extdata'); testres <- parse_sources(examplePath, extension="dct", silent=TRUE); testthat::expect_equal(testres$deductiveCodeTrees$behavior_xl67k7w8j$intention_71vr5q3q$attitude_71vqm37n$label, "Attitude"); }); ###----------------------------------------------------------------------------- testthat::test_that("Sources are exported to html properly", { # devtools::load_all(); # rock::opts$set(debug = TRUE); examplePath <- file.path(system.file(package="rock"), 'extdata'); rock::opts$set(warnForMultipleAesthetics = FALSE); testres <- parse_sources(examplePath, extension="rock", silent=TRUE); testres <- export_to_html(testres); testthat::expect_true(grepl('[[grandchildCode2]]', testres[["example-1.rock"]], fixed=TRUE)); }); ###----------------------------------------------------------------------------- testthat::test_that("Coded fragments are collected properly", { examplePath <- file.path(system.file(package="rock"), 'extdata'); rock::opts$set(warnForMultipleAesthetics = FALSE); testres_parsed <- parse_sources(examplePath, extension="rock", silent=TRUE); testres <- collect_coded_fragments(testres_parsed); testthat::expect_true(grepl('\n#### Topic2 *(path: codes>Topic2)*\n\n-----\n\n\n\n**Source: `longer-test.rock`**\n\n