|
1 | 1 | # library(testthat); library(rds2cpp); source("setup.R"); source("test-other.R") |
2 | 2 |
|
3 | 3 | test_that("length extraction works correctly", { |
4 | | - # Remember this advances past the first byte. |
5 | | - expect_identical(rds2cpp::parse_length(as.raw(c(0, 0, 0, 0, 16))), 16) |
6 | | - expect_identical(rds2cpp::parse_length(as.raw(c(0, 0, 0, 255, 16))), 255 * 256 + 16) |
7 | | - expect_identical(rds2cpp::parse_length(as.raw(c(0, 0, 10, 255, 16))), 10 * 256^2 + 255 * 256 + 16) |
8 | | - expect_identical(rds2cpp::parse_length(as.raw(c(0, 5, 10, 255, 16))), 5 * 256^3 + 10 * 256^2 + 255 * 256 + 16) |
9 | | - |
10 | | - expect_error(rds2cpp::parse_length(as.raw(c(0, 255, 0, 0, 0)), "should be non-negative")) |
11 | | - expect_identical(rds2cpp::parse_length(as.raw(c(0, 255, 255, 255, 255, 0, 0, 0, 1, 0, 0, 0, 1))), 2^32 + 1) |
12 | | - expect_identical(rds2cpp::parse_length(as.raw(c(0, 255, 255, 255, 255, 0, 2, 0, 4, 0, 6, 0, 8))), 2 * 256^ 6 + 4 * 256^4 + 6 * 256^2 + 8) |
| 4 | + expect_identical(rds2cpp::parse_length(as.raw(c(0, 0, 0, 16))), 16) |
| 5 | + expect_identical(rds2cpp::parse_length(as.raw(c(0, 0, 255, 16))), 255 * 256 + 16) |
| 6 | + expect_identical(rds2cpp::parse_length(as.raw(c(0, 10, 255, 16))), 10 * 256^2 + 255 * 256 + 16) |
| 7 | + expect_identical(rds2cpp::parse_length(as.raw(c(5, 10, 255, 16))), 5 * 256^3 + 10 * 256^2 + 255 * 256 + 16) |
| 8 | + |
| 9 | + expect_error(rds2cpp::parse_length(as.raw(c(255, 0, 0, 0)), "should be non-negative")) |
| 10 | + expect_identical(rds2cpp::parse_length(as.raw(c(255, 255, 255, 255, 0, 0, 0, 1, 0, 0, 0, 1))), 2^32 + 1) |
| 11 | + expect_identical(rds2cpp::parse_length(as.raw(c(255, 255, 255, 255, 0, 2, 0, 4, 0, 6, 0, 8))), 2 * 256^ 6 + 4 * 256^4 + 6 * 256^2 + 8) |
13 | 12 | }) |
14 | 13 |
|
15 | 14 | test_that("string extraction works correctly", { |
16 | | - expect_identical(rds2cpp::parse_single_string(as.raw(c(0, 0, 0, 2^7, 9, 0, 0, 0, 5, charToRaw('ABCDE')))), list("ABCDE", "UTF-8")) |
17 | | - expect_identical(rds2cpp::parse_single_string(as.raw(c(0, 0, 0, 2^6, 9, 0, 0, 0, 5, charToRaw('ABCDE')))), list("ABCDE", "latin1")) |
18 | | - expect_identical(rds2cpp::parse_single_string(as.raw(c(0, 0, 2^2, 0, 9, 0, 0, 0, 5, charToRaw('ABCDE')))), list("ABCDE", "unknown")) |
19 | | - expect_identical(rds2cpp::parse_single_string(as.raw(c(0, 0, 0, 2^5, 9, 0, 0, 0, 5, charToRaw('ABCDE')))), list("ABCDE", "bytes")) |
20 | | - |
21 | | - expect_identical(rds2cpp::parse_single_string(as.raw(c(0, 0, 0, 2^7, 9, 0, 0, 0, 0))), list("", "UTF-8")) |
22 | | - expect_identical(rds2cpp::parse_single_string(as.raw(c(0, 0, 0, 2^5, 9, 255, 255, 255, 255))), NA_character_) |
23 | | - expect_error(rds2cpp::parse_single_string(as.raw(c(0, 0, 0, 2^5, 9, 255, 0, 0, 0))), "non-negative"); |
| 15 | + expect_identical(rds2cpp::parse_single_string(as.raw(c(0, 0, 2^7, 9, 0, 0, 0, 5, charToRaw('ABCDE')))), list("ABCDE", "UTF-8")) |
| 16 | + expect_identical(rds2cpp::parse_single_string(as.raw(c(0, 0, 2^6, 9, 0, 0, 0, 5, charToRaw('ABCDE')))), list("ABCDE", "latin1")) |
| 17 | + expect_identical(rds2cpp::parse_single_string(as.raw(c(0, 2^2, 0, 9, 0, 0, 0, 5, charToRaw('ABCDE')))), list("ABCDE", "unknown")) |
| 18 | + expect_identical(rds2cpp::parse_single_string(as.raw(c(0, 0, 2^5, 9, 0, 0, 0, 5, charToRaw('ABCDE')))), list("ABCDE", "bytes")) |
| 19 | + |
| 20 | + expect_identical(rds2cpp::parse_single_string(as.raw(c(0, 0, 2^7, 9, 0, 0, 0, 0))), list("", "UTF-8")) |
| 21 | + expect_identical(rds2cpp::parse_single_string(as.raw(c(0, 0, 2^5, 9, 255, 255, 255, 255))), NA_character_) |
| 22 | + expect_error(rds2cpp::parse_single_string(as.raw(c(0, 0, 2^5, 9, 255, 0, 0, 0))), "non-negative"); |
24 | 23 | }) |
25 | 24 |
|
26 | 25 | test_that("RDS preamble extraction works correctly", { |
|
0 commit comments