1///|
2test "Encode single byte" {
3 (a : Array[Byte], b : Array[Byte], loc~ : SourceLoc = _) -> Unit raise Error
Asserts that two values are equal. If they are not equal, raises a failure
with a message containing the source location and the values being compared.
Parameters:
a : First value to compare.
b : Second value to compare.
loc : Source location information to include in failure messages. This is
usually automatically provided by the compiler.
Throws a Failure error if the values are not equal, with a message showing
the location of the failing assertion and the actual values that were
compared.
Example:
assert_eq(1, 1)
assert_eq("hello", "hello")
assert_eq((numbers : Array[UInt]) -> Array[Byte]
Encodes an array of unsigned integers into Variable Length Quantity (VLQ) byte format.
to_vlq([0x7F]), [0x7F])
4}
5
6///|
7test "Encode multiple bytes" {
8 (a : Array[Byte], b : Array[Byte], loc~ : SourceLoc = _) -> Unit raise Error
Asserts that two values are equal. If they are not equal, raises a failure
with a message containing the source location and the values being compared.
Parameters:
a : First value to compare.
b : Second value to compare.
loc : Source location information to include in failure messages. This is
usually automatically provided by the compiler.
Throws a Failure error if the values are not equal, with a message showing
the location of the failing assertion and the actual values that were
compared.
Example:
assert_eq(1, 1)
assert_eq("hello", "hello")
assert_eq((numbers : Array[UInt]) -> Array[Byte]
Encodes an array of unsigned integers into Variable Length Quantity (VLQ) byte format.
to_vlq([0x4000]), [0x81, 0x80, 0x00])
9}
10
11///|
12test "Decode single byte" {
13 (a : Result[Array[UInt], VlqError], b : Result[Array[UInt], VlqError], loc~ : SourceLoc = _) -> Unit raise Error
Asserts that two values are equal. If they are not equal, raises a failure
with a message containing the source location and the values being compared.
Parameters:
a : First value to compare.
b : Second value to compare.
loc : Source location information to include in failure messages. This is
usually automatically provided by the compiler.
Throws a Failure error if the values are not equal, with a message showing
the location of the failing assertion and the actual values that were
compared.
Example:
assert_eq(1, 1)
assert_eq("hello", "hello")
assert_eq(try? (bytes : Array[Byte]) -> Array[UInt] raise VlqError
Decodes Variable Length Quantity (VLQ) bytes back into unsigned integers.
Errors:
- Overflow: If a number exceeds 0x01FFFFFF (28 bits)
- IncompleteSequence: If the sequence ends with a continuation byte
from_vlq([0x7F]), (Array[UInt]) -> Result[Array[UInt], VlqError]
Ok([0x7F]))
14}
15
16///|
17test "Decode incomplete standard sequence" {
18 let Result[Array[UInt], VlqError]
result = try? (bytes : Array[Byte]) -> Array[UInt] raise VlqError
Decodes Variable Length Quantity (VLQ) bytes back into unsigned integers.
Errors:
- Overflow: If a number exceeds 0x01FFFFFF (28 bits)
- IncompleteSequence: If the sequence ends with a continuation byte
from_vlq([0x81])
19 (x : Bool, loc~ : SourceLoc = _) -> Unit raise Error
Asserts that the given boolean value is true. Throws an error with source
location information if the assertion fails.
Parameters:
condition : The boolean value to be checked.
location : The source location where the assertion is made. Defaults to
the current location.
Throws a Failure error with a descriptive message including the source
location if the condition is false.
Example:
assert_true(true)
assert_true(Result[Array[UInt], VlqError]
result is (VlqError) -> Result[Array[UInt], VlqError]
Err(VlqError
IncompleteSequence))
20}
21
22///|
23test "Decode overflow standard sequence" {
24 let Result[Array[UInt], VlqError]
result = try? (bytes : Array[Byte]) -> Array[UInt] raise VlqError
Decodes Variable Length Quantity (VLQ) bytes back into unsigned integers.
Errors:
- Overflow: If a number exceeds 0x01FFFFFF (28 bits)
- IncompleteSequence: If the sequence ends with a continuation byte
from_vlq([0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F])
25 (x : Bool, loc~ : SourceLoc = _) -> Unit raise Error
Asserts that the given boolean value is true. Throws an error with source
location information if the assertion fails.
Parameters:
condition : The boolean value to be checked.
location : The source location where the assertion is made. Defaults to
the current location.
Throws a Failure error with a descriptive message including the source
location if the condition is false.
Example:
assert_true(true)
assert_true(Result[Array[UInt], VlqError]
result is (VlqError) -> Result[Array[UInt], VlqError]
Err(VlqError
Overflow))
26}
27
28///|
29test "Encode and decode roundtrip" {
30 let Array[UInt]
numbers = [0x7FU, 0x4000, 0x01FFFFFF]
31 let Array[Byte]
encoded = (numbers : Array[UInt]) -> Array[Byte]
Encodes an array of unsigned integers into Variable Length Quantity (VLQ) byte format.
to_vlq(Array[UInt]
numbers)
32 let Result[Array[UInt], VlqError]
decoded = try? (bytes : Array[Byte]) -> Array[UInt] raise VlqError
Decodes Variable Length Quantity (VLQ) bytes back into unsigned integers.
Errors:
- Overflow: If a number exceeds 0x01FFFFFF (28 bits)
- IncompleteSequence: If the sequence ends with a continuation byte
from_vlq(Array[Byte]
encoded)
33 (a : Result[Array[UInt], VlqError], b : Result[Array[UInt], VlqError], loc~ : SourceLoc = _) -> Unit raise Error
Asserts that two values are equal. If they are not equal, raises a failure
with a message containing the source location and the values being compared.
Parameters:
a : First value to compare.
b : Second value to compare.
loc : Source location information to include in failure messages. This is
usually automatically provided by the compiler.
Throws a Failure error if the values are not equal, with a message showing
the location of the failing assertion and the actual values that were
compared.
Example:
assert_eq(1, 1)
assert_eq("hello", "hello")
assert_eq(Result[Array[UInt], VlqError]
decoded, (Array[UInt]) -> Result[Array[UInt], VlqError]
Ok(Array[UInt]
numbers))
34}
35
36///|
37test "Decode empty array" {
38 let Result[Array[UInt], VlqError]
result = try? (bytes : Array[Byte]) -> Array[UInt] raise VlqError
Decodes Variable Length Quantity (VLQ) bytes back into unsigned integers.
Errors:
- Overflow: If a number exceeds 0x01FFFFFF (28 bits)
- IncompleteSequence: If the sequence ends with a continuation byte
from_vlq([])
39 (a : Result[Array[UInt], VlqError], b : Result[Array[UInt], VlqError], loc~ : SourceLoc = _) -> Unit raise Error
Asserts that two values are equal. If they are not equal, raises a failure
with a message containing the source location and the values being compared.
Parameters:
a : First value to compare.
b : Second value to compare.
loc : Source location information to include in failure messages. This is
usually automatically provided by the compiler.
Throws a Failure error if the values are not equal, with a message showing
the location of the failing assertion and the actual values that were
compared.
Example:
assert_eq(1, 1)
assert_eq("hello", "hello")
assert_eq(Result[Array[UInt], VlqError]
result, (Array[UInt]) -> Result[Array[UInt], VlqError]
Ok([]))
40}
41
42///|
43test "Base64 编码" {
44 (a : String, b : String, loc~ : SourceLoc = _) -> Unit raise Error
Asserts that two values are equal. If they are not equal, raises a failure
with a message containing the source location and the values being compared.
Parameters:
a : First value to compare.
b : Second value to compare.
loc : Source location information to include in failure messages. This is
usually automatically provided by the compiler.
Throws a Failure error if the values are not equal, with a message showing
the location of the failing assertion and the actual values that were
compared.
Example:
assert_eq(1, 1)
assert_eq("hello", "hello")
assert_eq((numbers : Array[Int]) -> String
Encodes an array of signed integers into Base64 VLQ format.
Example
let numbers = [1, -1, 16]
let encoded = to_base64_vlq(numbers)
inspect(encoded, content="CDgB")
to_base64_vlq([0]), "A")
45 (a : String, b : String, loc~ : SourceLoc = _) -> Unit raise Error
Asserts that two values are equal. If they are not equal, raises a failure
with a message containing the source location and the values being compared.
Parameters:
a : First value to compare.
b : Second value to compare.
loc : Source location information to include in failure messages. This is
usually automatically provided by the compiler.
Throws a Failure error if the values are not equal, with a message showing
the location of the failing assertion and the actual values that were
compared.
Example:
assert_eq(1, 1)
assert_eq("hello", "hello")
assert_eq((numbers : Array[Int]) -> String
Encodes an array of signed integers into Base64 VLQ format.
Example
let numbers = [1, -1, 16]
let encoded = to_base64_vlq(numbers)
inspect(encoded, content="CDgB")
to_base64_vlq([1]), "C")
46 (a : String, b : String, loc~ : SourceLoc = _) -> Unit raise Error
Asserts that two values are equal. If they are not equal, raises a failure
with a message containing the source location and the values being compared.
Parameters:
a : First value to compare.
b : Second value to compare.
loc : Source location information to include in failure messages. This is
usually automatically provided by the compiler.
Throws a Failure error if the values are not equal, with a message showing
the location of the failing assertion and the actual values that were
compared.
Example:
assert_eq(1, 1)
assert_eq("hello", "hello")
assert_eq((numbers : Array[Int]) -> String
Encodes an array of signed integers into Base64 VLQ format.
Example
let numbers = [1, -1, 16]
let encoded = to_base64_vlq(numbers)
inspect(encoded, content="CDgB")
to_base64_vlq([-1]), "D")
47 (a : String, b : String, loc~ : SourceLoc = _) -> Unit raise Error
Asserts that two values are equal. If they are not equal, raises a failure
with a message containing the source location and the values being compared.
Parameters:
a : First value to compare.
b : Second value to compare.
loc : Source location information to include in failure messages. This is
usually automatically provided by the compiler.
Throws a Failure error if the values are not equal, with a message showing
the location of the failing assertion and the actual values that were
compared.
Example:
assert_eq(1, 1)
assert_eq("hello", "hello")
assert_eq((numbers : Array[Int]) -> String
Encodes an array of signed integers into Base64 VLQ format.
Example
let numbers = [1, -1, 16]
let encoded = to_base64_vlq(numbers)
inspect(encoded, content="CDgB")
to_base64_vlq([16]), "gB")
48 (a : String, b : String, loc~ : SourceLoc = _) -> Unit raise Error
Asserts that two values are equal. If they are not equal, raises a failure
with a message containing the source location and the values being compared.
Parameters:
a : First value to compare.
b : Second value to compare.
loc : Source location information to include in failure messages. This is
usually automatically provided by the compiler.
Throws a Failure error if the values are not equal, with a message showing
the location of the failing assertion and the actual values that were
compared.
Example:
assert_eq(1, 1)
assert_eq("hello", "hello")
assert_eq((numbers : Array[Int]) -> String
Encodes an array of signed integers into Base64 VLQ format.
Example
let numbers = [1, -1, 16]
let encoded = to_base64_vlq(numbers)
inspect(encoded, content="CDgB")
to_base64_vlq([-16]), "hB")
49}
50
51///|
52test "Base64 Encoding" {
53 (a : String, b : String, loc~ : SourceLoc = _) -> Unit raise Error
Asserts that two values are equal. If they are not equal, raises a failure
with a message containing the source location and the values being compared.
Parameters:
a : First value to compare.
b : Second value to compare.
loc : Source location information to include in failure messages. This is
usually automatically provided by the compiler.
Throws a Failure error if the values are not equal, with a message showing
the location of the failing assertion and the actual values that were
compared.
Example:
assert_eq(1, 1)
assert_eq("hello", "hello")
assert_eq((numbers : Array[Int]) -> String
Encodes an array of signed integers into Base64 VLQ format.
Example
let numbers = [1, -1, 16]
let encoded = to_base64_vlq(numbers)
inspect(encoded, content="CDgB")
to_base64_vlq([1, -1, 16]), "CDgB")
54}
55
56///|
57test "Base64 Decoding" {
58 (a : Result[Array[Int], VlqError], b : Result[Array[Int], VlqError], loc~ : SourceLoc = _) -> Unit raise Error
Asserts that two values are equal. If they are not equal, raises a failure
with a message containing the source location and the values being compared.
Parameters:
a : First value to compare.
b : Second value to compare.
loc : Source location information to include in failure messages. This is
usually automatically provided by the compiler.
Throws a Failure error if the values are not equal, with a message showing
the location of the failing assertion and the actual values that were
compared.
Example:
assert_eq(1, 1)
assert_eq("hello", "hello")
assert_eq(try? (s : String) -> Array[Int] raise VlqError
Decodes a Base64 VLQ string back into signed integers.
Example
let encoded = "CDgB"
let decoded = try? from_base64_vlq(encoded)
inspect(decoded, content="Ok([1, -1, 16])")
Errors
IncompleteSequence: If the string ends with a continuation character
InvalidBase64Character: If an invalid Base64 character is encountered
from_base64_vlq("A"), (Array[Int]) -> Result[Array[Int], VlqError]
Ok([0]))
59 (a : Result[Array[Int], VlqError], b : Result[Array[Int], VlqError], loc~ : SourceLoc = _) -> Unit raise Error
Asserts that two values are equal. If they are not equal, raises a failure
with a message containing the source location and the values being compared.
Parameters:
a : First value to compare.
b : Second value to compare.
loc : Source location information to include in failure messages. This is
usually automatically provided by the compiler.
Throws a Failure error if the values are not equal, with a message showing
the location of the failing assertion and the actual values that were
compared.
Example:
assert_eq(1, 1)
assert_eq("hello", "hello")
assert_eq(try? (s : String) -> Array[Int] raise VlqError
Decodes a Base64 VLQ string back into signed integers.
Example
let encoded = "CDgB"
let decoded = try? from_base64_vlq(encoded)
inspect(decoded, content="Ok([1, -1, 16])")
Errors
IncompleteSequence: If the string ends with a continuation character
InvalidBase64Character: If an invalid Base64 character is encountered
from_base64_vlq("C"), (Array[Int]) -> Result[Array[Int], VlqError]
Ok([1]))
60 (a : Result[Array[Int], VlqError], b : Result[Array[Int], VlqError], loc~ : SourceLoc = _) -> Unit raise Error
Asserts that two values are equal. If they are not equal, raises a failure
with a message containing the source location and the values being compared.
Parameters:
a : First value to compare.
b : Second value to compare.
loc : Source location information to include in failure messages. This is
usually automatically provided by the compiler.
Throws a Failure error if the values are not equal, with a message showing
the location of the failing assertion and the actual values that were
compared.
Example:
assert_eq(1, 1)
assert_eq("hello", "hello")
assert_eq(try? (s : String) -> Array[Int] raise VlqError
Decodes a Base64 VLQ string back into signed integers.
Example
let encoded = "CDgB"
let decoded = try? from_base64_vlq(encoded)
inspect(decoded, content="Ok([1, -1, 16])")
Errors
IncompleteSequence: If the string ends with a continuation character
InvalidBase64Character: If an invalid Base64 character is encountered
from_base64_vlq("D"), (Array[Int]) -> Result[Array[Int], VlqError]
Ok([-1]))
61 (a : Result[Array[Int], VlqError], b : Result[Array[Int], VlqError], loc~ : SourceLoc = _) -> Unit raise Error
Asserts that two values are equal. If they are not equal, raises a failure
with a message containing the source location and the values being compared.
Parameters:
a : First value to compare.
b : Second value to compare.
loc : Source location information to include in failure messages. This is
usually automatically provided by the compiler.
Throws a Failure error if the values are not equal, with a message showing
the location of the failing assertion and the actual values that were
compared.
Example:
assert_eq(1, 1)
assert_eq("hello", "hello")
assert_eq(try? (s : String) -> Array[Int] raise VlqError
Decodes a Base64 VLQ string back into signed integers.
Example
let encoded = "CDgB"
let decoded = try? from_base64_vlq(encoded)
inspect(decoded, content="Ok([1, -1, 16])")
Errors
IncompleteSequence: If the string ends with a continuation character
InvalidBase64Character: If an invalid Base64 character is encountered
from_base64_vlq("gB"), (Array[Int]) -> Result[Array[Int], VlqError]
Ok([16]))
62 (a : Result[Array[Int], VlqError], b : Result[Array[Int], VlqError], loc~ : SourceLoc = _) -> Unit raise Error
Asserts that two values are equal. If they are not equal, raises a failure
with a message containing the source location and the values being compared.
Parameters:
a : First value to compare.
b : Second value to compare.
loc : Source location information to include in failure messages. This is
usually automatically provided by the compiler.
Throws a Failure error if the values are not equal, with a message showing
the location of the failing assertion and the actual values that were
compared.
Example:
assert_eq(1, 1)
assert_eq("hello", "hello")
assert_eq(try? (s : String) -> Array[Int] raise VlqError
Decodes a Base64 VLQ string back into signed integers.
Example
let encoded = "CDgB"
let decoded = try? from_base64_vlq(encoded)
inspect(decoded, content="Ok([1, -1, 16])")
Errors
IncompleteSequence: If the string ends with a continuation character
InvalidBase64Character: If an invalid Base64 character is encountered
from_base64_vlq("hB"), (Array[Int]) -> Result[Array[Int], VlqError]
Ok([-16]))
63 (obj : &Show, content~ : String, loc~ : SourceLoc = _, args_loc~ : ArgsLoc = _) -> Unit raise InspectError
Tests if the string representation of an object matches the expected content.
Used primarily in test cases to verify the correctness of Show
implementations and program outputs.
Parameters:
object : The object to be inspected. Must implement the Show trait.
content : The expected string representation of the object. Defaults to
an empty string.
location : Source code location information for error reporting.
Automatically provided by the compiler.
arguments_location : Location information for function arguments in
source code. Automatically provided by the compiler.
Throws an InspectError if the actual string representation of the object
does not match the expected content. The error message includes detailed
information about the mismatch, including source location and both expected
and actual values.
Example:
inspect(42, content="42")
inspect("hello", content="hello")
inspect([1, 2, 3], content="[1, 2, 3]")
inspect(try? (s : String) -> Array[Int] raise VlqError
Decodes a Base64 VLQ string back into signed integers.
Example
let encoded = "CDgB"
let decoded = try? from_base64_vlq(encoded)
inspect(decoded, content="Ok([1, -1, 16])")
Errors
IncompleteSequence: If the string ends with a continuation character
InvalidBase64Character: If an invalid Base64 character is encountered
from_base64_vlq("2H"), String
content="Ok([123])")
64 (obj : &Show, content~ : String, loc~ : SourceLoc = _, args_loc~ : ArgsLoc = _) -> Unit raise InspectError
Tests if the string representation of an object matches the expected content.
Used primarily in test cases to verify the correctness of Show
implementations and program outputs.
Parameters:
object : The object to be inspected. Must implement the Show trait.
content : The expected string representation of the object. Defaults to
an empty string.
location : Source code location information for error reporting.
Automatically provided by the compiler.
arguments_location : Location information for function arguments in
source code. Automatically provided by the compiler.
Throws an InspectError if the actual string representation of the object
does not match the expected content. The error message includes detailed
information about the mismatch, including source location and both expected
and actual values.
Example:
inspect(42, content="42")
inspect("hello", content="hello")
inspect([1, 2, 3], content="[1, 2, 3]")
inspect(try? (s : String) -> Array[Int] raise VlqError
Decodes a Base64 VLQ string back into signed integers.
Example
let encoded = "CDgB"
let decoded = try? from_base64_vlq(encoded)
inspect(decoded, content="Ok([1, -1, 16])")
Errors
IncompleteSequence: If the string ends with a continuation character
InvalidBase64Character: If an invalid Base64 character is encountered
from_base64_vlq("qxmvrH"), String
content="Ok([123456789])")
65 (a : Result[Array[Int], VlqError], b : Result[Array[Int], VlqError], loc~ : SourceLoc = _) -> Unit raise Error
Asserts that two values are equal. If they are not equal, raises a failure
with a message containing the source location and the values being compared.
Parameters:
a : First value to compare.
b : Second value to compare.
loc : Source location information to include in failure messages. This is
usually automatically provided by the compiler.
Throws a Failure error if the values are not equal, with a message showing
the location of the failing assertion and the actual values that were
compared.
Example:
assert_eq(1, 1)
assert_eq("hello", "hello")
assert_eq(try? (s : String) -> Array[Int] raise VlqError
Decodes a Base64 VLQ string back into signed integers.
Example
let encoded = "CDgB"
let decoded = try? from_base64_vlq(encoded)
inspect(decoded, content="Ok([1, -1, 16])")
Errors
IncompleteSequence: If the string ends with a continuation character
InvalidBase64Character: If an invalid Base64 character is encountered
from_base64_vlq("2HwcqxB"), (Array[Int]) -> Result[Array[Int], VlqError]
Ok([123, 456, 789]))
66}
67
68///|
69test "Base64 Encoding with multiple numbers" {
70 (a : Result[Array[Int], VlqError], b : Result[Array[Int], VlqError], loc~ : SourceLoc = _) -> Unit raise Error
Asserts that two values are equal. If they are not equal, raises a failure
with a message containing the source location and the values being compared.
Parameters:
a : First value to compare.
b : Second value to compare.
loc : Source location information to include in failure messages. This is
usually automatically provided by the compiler.
Throws a Failure error if the values are not equal, with a message showing
the location of the failing assertion and the actual values that were
compared.
Example:
assert_eq(1, 1)
assert_eq("hello", "hello")
assert_eq(try? (s : String) -> Array[Int] raise VlqError
Decodes a Base64 VLQ string back into signed integers.
Example
let encoded = "CDgB"
let decoded = try? from_base64_vlq(encoded)
inspect(decoded, content="Ok([1, -1, 16])")
Errors
IncompleteSequence: If the string ends with a continuation character
InvalidBase64Character: If an invalid Base64 character is encountered
from_base64_vlq("CDgB"), (Array[Int]) -> Result[Array[Int], VlqError]
Ok([1, -1, 16]))
71}
72
73///|
74test "Incomplete Base64 sequence" {
75 let Result[Array[Int], VlqError]
result = try? (s : String) -> Array[Int] raise VlqError
Decodes a Base64 VLQ string back into signed integers.
Example
let encoded = "CDgB"
let decoded = try? from_base64_vlq(encoded)
inspect(decoded, content="Ok([1, -1, 16])")
Errors
IncompleteSequence: If the string ends with a continuation character
InvalidBase64Character: If an invalid Base64 character is encountered
from_base64_vlq("g") // 'g' 的连续位是 1
76 (x : Bool, loc~ : SourceLoc = _) -> Unit raise Error
Asserts that the given boolean value is true. Throws an error with source
location information if the assertion fails.
Parameters:
condition : The boolean value to be checked.
location : The source location where the assertion is made. Defaults to
the current location.
Throws a Failure error with a descriptive message including the source
location if the condition is false.
Example:
assert_true(true)
assert_true(Result[Array[Int], VlqError]
result is (VlqError) -> Result[Array[Int], VlqError]
Err(VlqError
IncompleteSequence))
77}
78
79///|
80test "Invalid Base64 character" {
81 let Result[Array[Int], VlqError]
result = try? (s : String) -> Array[Int] raise VlqError
Decodes a Base64 VLQ string back into signed integers.
Example
let encoded = "CDgB"
let decoded = try? from_base64_vlq(encoded)
inspect(decoded, content="Ok([1, -1, 16])")
Errors
IncompleteSequence: If the string ends with a continuation character
InvalidBase64Character: If an invalid Base64 character is encountered
from_base64_vlq("A!B")
82 (x : Bool, loc~ : SourceLoc = _) -> Unit raise Error
Asserts that the given boolean value is true. Throws an error with source
location information if the assertion fails.
Parameters:
condition : The boolean value to be checked.
location : The source location where the assertion is made. Defaults to
the current location.
Throws a Failure error with a descriptive message including the source
location if the condition is false.
Example:
assert_true(true)
assert_true(Result[Array[Int], VlqError]
result is (VlqError) -> Result[Array[Int], VlqError]
Err((Char) -> VlqError
InvalidBase64Character('!')))
83}
84