Skip to content

Instantly share code, notes, and snippets.

@jayjacobs
Last active July 31, 2016 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jayjacobs/ca53a484d1b8d7217ef8b4a3ecc5c00b to your computer and use it in GitHub Desktop.
Save jayjacobs/ca53a484d1b8d7217ef8b4a3ecc5c00b to your computer and use it in GitHub Desktop.
getting public suffix list tests.
connection <- url("https://raw.githubusercontent.com/publicsuffix/list/master/tests/test_psl.txt", method = "libcurl")
results <- readLines(connection)
close(connection)
justtests <- grep('checkPublicSuffix\\(', results, value = TRUE)
alltests <- do.call(rbind, lapply(strsplit(justtests, "'", fixed = TRUE), function(line) {
data.frame(domain=line[2], result=line[4])
}))
domains <- suffix_extract(alltests$domain)
rez1 <-ifelse(!is.na(domains$domain), paste0(domains$domain, "."), "")
rez <- ifelse(!is.na(domains$suffix), paste0(rez1, domains$suffix), NA)
fullrez <- data.frame(got = rez, expected = alltests$result, stringsAsFactors = FALSE)
fullrez$check <- fullrez$got == fullrez$expected
fullrez$check <- ifelse(is.na(fullrez$got) & is.na(fullrez$expected), TRUE, fullrez$check)
fullrez$check <- ifelse(is.na(fullrez$check), FALSE, fullrez$check)
cat("Failed:", sum(!fullrez$check), "out of", nrow(fullrez))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment