tests/testthat/test.lex_token2.R

#! /usr/bin/env Rscript

library(testthat)
library(rly)

context("Tests for tokens of wrong type")

Lexer <- R6::R6Class("Lexer",
  public = list(
    tokens = 'NUMBER PLUS MINUS',
    t_PLUS = '\\+',
    t_MINUS = '-',
    t_NUMBER = '\\d+',
    t_ignore = " \t",
    t_error = function(t) { }
  )
)

test_that("comment", {
  expect_output(expect_error(rly::lex(Lexer), "Can't build lexer"),
  "ERROR .* Bad token name 'NUMBER PLUS MINUS'")
})

Try the rly package in your browser

Any scripts or data that you put into this service are public.

rly documentation built on May 8, 2022, 5:05 p.m.