eflats <- c("e_,, e_, e_ e_' e_''", "e_1 e_2 e_3 e_4 e_5") efchord <- gsub(" ", "", eflats) x <- purrr::map(c(eflats, efchord), ~phrase(.x, 4)) y <- c(rep("4 4 4 4 4", 2), rep("4", 2)) test_that("phrase returns as expected", { purrr::walk(x, ~expect_is(.x, "phrase")) purrr::walk2(as.character(x), y, ~expect_equal(.x, .y)) expect_is(print(x[[1]]), "NULL") expect_identical(phrase(c("b_", "c"), 1), phrase("b_ c", 1)) expect_identical(as.character(p("c d", "8x 8^", 1)), "\\deadNote 8 8\\bendAfter #+6") expect_equal(as.character(p("de_' aa_,", 1)), "1 1") expect_equal(as.character(p("ee_' a_a#,", "2")), "2 2") expect_equal(as.character(p("d,, e_e_ a_' b_'d", "1 2 4.. 8.")), "1 2 4.. 8.") y <- "1 2 4.. 8." expect_equal( as.character(p("d,, e_e_ a_' b_'d", "1 2 4.. 8.", "1 21 3 43")), y) expect_equal( as.character(p("d1 e_3e_ a_' b_'d", "1 2 4.. 8.", "1 21 3 43")), y) n <- "d,,e_e_3 a_4b_4d" y <- "2 2" expect_equal(as.character(p(n, "2 2", "3 3")), y) expect_equal(as.character(p(n, "2*2", "3*2")), y) expect_equal(as.character(p(n, 2, "3 321")), y) x1 <- phrase("c b, c", "4. 8( 8)", "5 5 5") # direction implies hammer on x2 <- phrase("b2 c d", "4( 4)- 2", "5 5 5") # hammer and slide expect_equal(as.character(x1), "4. 8( 8)") expect_equal(as.character(x2), "4( 4)\\glissando 2") expect_error(p(1:2, 1, 1), "Invalid notes or chords found.") expect_error( p("a", 1:2, 1), paste("`info` must have the same number of timesteps as `notes`", "or a single value to repeat.") ) expect_error( p("a", 1, 1:2), paste("`string` must have the same number of timesteps as `notes`,", "or a single value to repeat, or be NULL.") ) expect_equal(.notesub("ees", simplify = TRUE), "es") expect_identical(p("a", 1), p("a", 1, NA)) expect_identical( p("c d e f g a b c'", 8, bar = NULL), p("c d e f g a b c'", 8, bar = FALSE) ) expect_identical( p("c d e f g a b c'", 8), gsub(" \\|$", "", p("c d e f g a b c'", 8, bar = TRUE)) ) expect_identical( p("c d e f g a b c'", 8), gsub(" \\\\bar \"\\|\\.\"$", "", p("c d e f g a b c'", 8, bar = "|.")) ) }) p1 <- phrase("c ec'g' ec'g'", "4 4 2") # no explicit strings (not recommended) p2 <- phrase("c ec4g4 ec4g4", "4 4 2") # same as above p3 <- phrase("c b, c", "4. 8( 8)", "5 5 5") # direction implies hammer on p4 <- phrase("b2 c d", "4( 4)- 2", "5 5 5") # hammer and slide p5 <- phrase("c ec'g'~ ec'g'", 1, "5 432 432") # tied chord p6 <- phrase("s r c ec'g'~ ec'g' r", 1, "5 x x 432 432 x") # add rests x <- list(p1, p2, p3, p4, p5, p6) y <- lapply(as.character(x), as_phrase) test_that("phrasey returns as expected", { expect_true(all(sapply(x, phrasey))) expect_true(all(sapply(as.character(x), phrasey))) expect_identical(x, y) expect_false(phrasey(1)) expect_false(phrasey("x")) expect_false(phrasey(""), "`phrase` is not phrasey.") expect_error(notify(p(as_music("at8"))), "Cannot notify phrases containing tuplets.") }) test_that("Other functions work on phrases as expected", { expect_equal(info_articulation(phrase("a b", "4-+ 4.[staccato]")), c("-+", "staccato")) expect_error(simplify_phrase(1), "Not a phrase.") })