tests/testthat/test-lex.R

context("lex")

test_that("lex() works", {
  sentence_patterns <- c(
    word        = "\\w+",
    whitespace  = "\\s+",
    fullstop    = "\\.",
    comma       = ","
  )

  sentence = "Hello there, Rstats."

  res <- lex(sentence, sentence_patterns)

  expect_equal(names(res) , c( 'word', 'whitespace',  'word', 'comma', 'whitespace',   'word', 'fullstop'))
  expect_equal(unname(res), c('Hello',         ' ',  'there',     ',',          ' ', 'Rstats',        '.'))

})
coolbutuseless/minilexer documentation built on May 14, 2019, 6:09 a.m.