From 767b5809bbf469ac4205c5a8c11102a587bd678c Mon Sep 17 00:00:00 2001 From: chainsawriot Date: Mon, 20 Nov 2023 15:51:10 +0100 Subject: [PATCH] Add tests ref #35 --- tests/testthat/test-docvars.R | 7 +++++++ tests/testthat/test-tokens_dist.R | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/tests/testthat/test-docvars.R b/tests/testthat/test-docvars.R index 7be2395..1b97add 100644 --- a/tests/testthat/test-docvars.R +++ b/tests/testthat/test-docvars.R @@ -20,3 +20,10 @@ test_that("meta retention", { expect_equal(test_corpus %>% tokens() %>% dfm() %>% meta("what"), "test") expect_equal(test_corpus %>% tokens() %>% tokens_proximity(pattern = "world") %>% dfm() %>% meta("what"), "test") }) + +test_that("docvars and meta methods", { + suppressPackageStartupMessages(library(quanteda)) + test <- c("hello world!") + expect_equal(tokens(test) %>% tokens_proximity("world") %>% docvars() %>% colnames(), "proximity") + expect_error(tokens(test) %>% tokens_proximity("world") %>% meta(), NA) +}) diff --git a/tests/testthat/test-tokens_dist.R b/tests/testthat/test-tokens_dist.R index fd83e5c..20e1c5c 100644 --- a/tests/testthat/test-tokens_dist.R +++ b/tests/testthat/test-tokens_dist.R @@ -42,3 +42,12 @@ test_that("Changing keywords", { expect_error(res2 <- tokens_proximity(res, "life"), NA) expect_equal(meta(res2, "keywords"), "life") }) + +test_that("token_proximity() only emit token_proximity #35", { + suppressPackageStartupMessages(library(quanteda)) + "this is my life" %>% tokens() %>% tokens_proximity("my") -> res + expect_equal(class(res), "tokens_with_proximity") # no tokens + expect_error(tokens_select(res, "life")) + expect_error(tokens_select(as.tokens(res), "life"), NA) +}) +