tests/testthat/test-regex.R

test_that("regex matches perfect example", {
  expect_equal(unlist(revise:::extract_sections('<span id = "hai">works</span>', is_span = TRUE)), c("hai" = "works"))
})

test_that("regex matches weird spacing", {
  expect_equal(unlist(
    revise:::extract_sections('<span id ="hai">works</span>', is_span = TRUE)
  ), c("hai" = "works"))})

test_that("regex matches no spacing", {
  expect_equal(unlist(
    revise:::extract_sections('<span id="hai">works</span>', is_span = TRUE)
    ),
    c("hai" = "works"))})

test_that("regex matches weird spacing 2", {
  expect_equal(unlist(
    revise:::extract_sections('<span id= "hai">works</span>', is_span = TRUE)
  ),
  c("hai" = "works"))})

test_that("regex handles other attributes in span tag:", {
  expect_equal(unlist(
    revise:::extract_sections('<span style="color:blue" id= "hai">works</span>', is_span = TRUE)
  ),
  c("hai" = "works"))})


test_that("regex handles different quotes:", {
  expect_equal(unlist(
    revise:::extract_sections("<span id= 'hai'>works</span>", is_span = TRUE)
  ),
  c("hai" = "works"))
  expect_equal(unlist(
    revise:::extract_sections("<span id= \"hai\">works</span>", is_span = TRUE)
  ),
  c("hai" = "works"))
  expect_equal(unlist(
    revise:::extract_sections("<span style=\"color:blue\" id= 'hai'>works</span>", is_span = TRUE)
  ),
  c("hai" = "works"))

  })

Try the revise package in your browser

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

revise documentation built on April 3, 2025, 11:47 p.m.