Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor: moon info #103

Merged
merged 2 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions crypto/chacha.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ fn flipWord(word : UInt) -> UInt {
b0 | b1 | b2 | b3
}

///|
test "flipWord" {
let word = 0x12345678U
let flipped = flipWord(word)
Expand Down Expand Up @@ -52,6 +53,7 @@ fn quarterRound(
state
}

///|
test "quarterRound" {
let state = FixedArray::make(16, 0U)
state[0] = 0x879531e0U
Expand Down Expand Up @@ -90,6 +92,7 @@ fn chachaBlockRound(state : FixedArray[UInt]) -> FixedArray[UInt] {
state8
}

///|
test "chachaBlockRound" {
let state = FixedArray::make(16, 0U)
state[0] = 0x61707865U
Expand Down Expand Up @@ -123,6 +126,7 @@ fn chachaBlockLoop(state : FixedArray[UInt], n : UInt) -> FixedArray[UInt] {
}
}

///|
test "chachaBlockLoop" {
let count = 1U
let key = FixedArray::make(8, 0U)
Expand Down Expand Up @@ -180,6 +184,7 @@ fn zipWith(
result
}

///|
test "zipWith" {
let state1 = FixedArray::make(4, 0U)
state1[0] = 1
Expand Down Expand Up @@ -229,6 +234,7 @@ fn chachaBlock(
flipState(combinedState)
}

///|
test "chachaBlock" {
let key = FixedArray::make(8, 0U)
key[0] = 0x00010203U
Expand Down Expand Up @@ -267,6 +273,7 @@ fn stateToBytes(state : FixedArray[UInt]) -> FixedArray[Byte] {
from_array(result)
}

///|
test "stateToBytes" {
let state = FixedArray::make(16, 0U)
state[0] = 0x879531e0
Expand Down
1 change: 1 addition & 0 deletions crypto/chacha_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

///|
test "chachaEncrypt" {
let key = FixedArray::make(8, 0U)
key[0] = 0
Expand Down
2 changes: 2 additions & 0 deletions crypto/md5.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ pub fn md5(data : FixedArray[Byte]) -> FixedArray[Byte] {
ctx.md5_compute()
}

///|
test "md5_wb" {
let hash = md5(
"The quick brown fox jumps over the lazy dog".to_bytes().to_fixedarray(),
Expand All @@ -244,6 +245,7 @@ test "md5_wb" {
)
}

///|
test {
let ctx = MD5Context::new()
md5_update(ctx, b"\x61".to_fixedarray())
Expand Down
2 changes: 2 additions & 0 deletions crypto/md5_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ fn md5test(s : String) -> String {
bytes_to_hex_string(@crypto.md5(s.to_bytes().to_fixedarray()))
}

///|
test "md5_rfc1321" { // testsuites in RFC1321
let hash = md5test("")
inspect!(hash, content="d41d8cd98f00b204e9800998ecf8427e")
Expand All @@ -38,6 +39,7 @@ test "md5_rfc1321" { // testsuites in RFC1321
inspect!(hash, content="903f43f5c1f384fc267110bf07caec04")
}

///|
test "md5_additional" { // Additional testsuites
let hash = md5test(
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
Expand Down
1 change: 1 addition & 0 deletions crypto/sha1_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
///|
let bytes_to_hex_string = @crypto.bytes_to_hex_string

///|
test "sha1" {
let a = "The quick brown fox jumps over the lazy dog"
inspect!(
Expand Down
1 change: 1 addition & 0 deletions crypto/sha224.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub fn sha224_from_iter(data : Iter[Byte]) -> FixedArray[Byte] {
arr_u32_to_u8be(ctx.sha256_compute().iter().take(7), 224)
}

///|
test {
// Sha224
assert_eq!(
Expand Down
1 change: 1 addition & 0 deletions crypto/sha224_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

///|
test "sha224-additional" {
assert_eq!(
sha224test(""),
Expand Down
1 change: 1 addition & 0 deletions crypto/sha256.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ pub fn sha256_from_iter(data : Iter[Byte]) -> FixedArray[Byte] {
arr_u32_to_u8be(ctx.sha256_compute().iter(), 256)
}

///|
test {
// Sha256
fn sha256_u32(data : FixedArray[Byte]) -> FixedArray[UInt] {
Expand Down
1 change: 1 addition & 0 deletions crypto/sha256_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ fn sha224test(s : String) -> String {
}

// additional
///|
test "sha256-additional" {
assert_eq!(
sha256test(""),
Expand Down
1 change: 1 addition & 0 deletions crypto/sm3.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ pub fn sm3_from_iter(data : Iter[Byte]) -> FixedArray[Byte] {
arr_u32_to_u8be(ctx.sm3_compute().iter(), 256)
}

///|
test {
fn sm3_u32(data : FixedArray[Byte]) -> FixedArray[UInt] {
let ctx = SM3Context::new()
Expand Down
1 change: 1 addition & 0 deletions crypto/sm3_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ fn sm3test(s : String) -> String {
}

// additional
///|
test "sm3-additional" {
assert_eq!(
sm3test(""),
Expand Down
18 changes: 18 additions & 0 deletions encoding/decoding_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

// lossy

///|
test "lossy decoding String (UTF16LE encoded) to String (buffer.write_bytes)" {
let src = "你好👀"
let buf = @buffer.new(size_hint=src.to_bytes().length())
Expand All @@ -28,6 +29,7 @@ test "lossy decoding String (UTF16LE encoded) to String (buffer.write_bytes)" {
inspect!(chars, content=src)
}

///|
test "lossy decoding String (UTF16LE encoded) to String (buffer.write_char)" {
let src = "👋再见"
let buf = @buffer.new(size_hint=10)
Expand All @@ -44,6 +46,7 @@ test "lossy decoding String (UTF16LE encoded) to String (buffer.write_char)" {
inspect!(chars, content=src)
}

///|
test "lossy decoding UTF16LE encoded data to String" {
let buf = @buffer.new(size_hint=10)
buf.write_bytes(b"\x60\x4f")
Expand All @@ -59,6 +62,7 @@ test "lossy decoding UTF16LE encoded data to String" {
inspect!(chars, content="你好👀")
}

///|
test "lossy decoding UTF16 (alias for UTF16LE) encoded data to String" {
let buf = @buffer.new(size_hint=20)
buf.write_bytes(b"\x65\x18")
Expand All @@ -78,6 +82,7 @@ test "lossy decoding UTF16 (alias for UTF16LE) encoded data to String" {
inspect!(chars, content="ᡥᠠᡳᡤᡳᠶᠠ")
}

///|
test "lossy decoding UTF16BE encoded data to String" {
let buf = @buffer.new(size_hint=10)
buf.write_bytes(b"\xd8\x3d\xdc\x08")
Expand All @@ -94,6 +99,7 @@ test "lossy decoding UTF16BE encoded data to String" {
inspect!(chars, content="🐈🐱🐇🐰")
}

///|
test "lossy decoding UTF8 encoded data to String" {
let buf = @buffer.new(size_hint=10)
buf.write_bytes(b"\xe4\xbd\xa0")
Expand All @@ -109,6 +115,7 @@ test "lossy decoding UTF8 encoded data to String" {
inspect!(chars, content="你好👀")
}

///|
test "lossy decoding UTF8 encoded bytes to String" {
let src = "👋再见"
let buf = @buffer.new(size_hint=10)
Expand All @@ -125,6 +132,7 @@ test "lossy decoding UTF8 encoded bytes to String" {
inspect!(chars, content=src)
}

///|
test "lossy decoding UTF8 encoded data" {
let src = "👋再见"
let buf = @buffer.new(size_hint=10)
Expand All @@ -141,6 +149,7 @@ test "lossy decoding UTF8 encoded data" {
inspect!(chars.iter().collect(), content="['👋', '再', '见']")
}

///|
test "lossy decoding UTF16LE encoded data with UTF8" {
let src = "跑步🏃游泳🏊"
let buf = @buffer.new(size_hint=10)
Expand All @@ -160,6 +169,7 @@ test "lossy decoding UTF16LE encoded data with UTF8" {
)
}

///|
test "lossy decoding UTF8 encoded data with UTF16LE" {
let src = "跑步🏃游泳🏊"
let buf = @buffer.new(size_hint=10)
Expand All @@ -179,6 +189,7 @@ test "lossy decoding UTF8 encoded data with UTF16LE" {
)
}

///|
test "lossy decoding UTF16BE encoded data with UTF8" {
let src = "跑步🏃游泳🏊"
let buf = @buffer.new(size_hint=10)
Expand All @@ -200,6 +211,7 @@ test "lossy decoding UTF16BE encoded data with UTF8" {
)
}

///|
test "lossy decoding UTF8 encoded data with UTF16BE" {
let src = "跑步🏃游泳🏊"
let buf = @buffer.new(size_hint=10)
Expand All @@ -219,6 +231,7 @@ test "lossy decoding UTF8 encoded data with UTF16BE" {
)
}

///|
test "lossy decoding UTF16LE encoded data with UTF16BE" {
let src = "跑步🏃游泳🏊"
let buf = @buffer.new(size_hint=10)
Expand All @@ -238,6 +251,7 @@ test "lossy decoding UTF16LE encoded data with UTF16BE" {
)
}

///|
test "lossy decoding UTF16BE encoded data with UTF16LE" {
let src = "跑步🏃游泳🏊"
let buf = @buffer.new(size_hint=10)
Expand All @@ -259,6 +273,7 @@ test "lossy decoding UTF16BE encoded data with UTF16LE" {

// strictly

///|
test "strictly decoding UTF16LE encoded data with UTF8" {
let src = "跑步🏃游泳🏊"
let buf = @buffer.new(size_hint=10)
Expand All @@ -280,6 +295,7 @@ test "strictly decoding UTF16LE encoded data with UTF8" {
)
}

///|
test "strictly decoding UTF8 encoded data with UTF16LE" {
let src = "跑步🏃游泳🏊"
let buf = @buffer.new(size_hint=10)
Expand All @@ -301,6 +317,7 @@ test "strictly decoding UTF8 encoded data with UTF16LE" {
)
}

///|
test "strictly decoding UTF8 encoded data with UTF16BE" {
let src = "跑步🏃游泳🏊"
let buf = @buffer.new(size_hint=10)
Expand All @@ -322,6 +339,7 @@ test "strictly decoding UTF8 encoded data with UTF16BE" {
)
}

///|
test "strictly decoding UTF16BE encoded data with UTF8" {
let src = "跑步🏃游泳🏊"
let buf = @buffer.new(size_hint=10)
Expand Down
12 changes: 12 additions & 0 deletions encoding/encoding_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

///|
test "encoding String to UTF8" {
let src = "你好👀"
let bytes = @encoding.encode(UTF8, src)
Expand All @@ -23,6 +24,7 @@ test "encoding String to UTF8" {
)
}

///|
test "encoding String to UTF16 (alias of UTF16LE)" {
let src = "LISP programmers know the value of everything"
let bytes = @encoding.encode(UTF16, src)
Expand All @@ -34,6 +36,7 @@ test "encoding String to UTF16 (alias of UTF16LE)" {
)
}

///|
test "encoding String to UTF16LE" {
let src = "and the cost of nothing"
let bytes = @encoding.encode(UTF16LE, src)
Expand All @@ -45,6 +48,7 @@ test "encoding String to UTF16LE" {
)
}

///|
test "encoding String to UTF16BE" {
let src = "λf.(λx.f(x x))(λx.f(x x))"
let bytes = @encoding.encode(UTF16BE, src)
Expand All @@ -56,6 +60,7 @@ test "encoding String to UTF16BE" {
)
}

///|
test "to_utf8_bytes" {
inspect!(
@encoding.to_utf8_bytes('A'),
Expand Down Expand Up @@ -83,6 +88,7 @@ test "to_utf8_bytes" {
)
}

///|
test "to_utf16_bytes (alias for to_utf16le_bytes)" {
inspect!(
@encoding.to_utf16_bytes('A'),
Expand Down Expand Up @@ -110,6 +116,7 @@ test "to_utf16_bytes (alias for to_utf16le_bytes)" {
)
}

///|
test "to_utf16le_bytes" {
inspect!(
@encoding.to_utf16le_bytes('A'),
Expand Down Expand Up @@ -137,6 +144,7 @@ test "to_utf16le_bytes" {
)
}

///|
test "to_utf16be_bytes" {
inspect!(
@encoding.to_utf16be_bytes('A'),
Expand Down Expand Up @@ -164,6 +172,7 @@ test "to_utf16be_bytes" {
)
}

///|
test "write_utf8_char" {
let buf = @buffer.new(size_hint=10)
@encoding.write_utf8_char(buf, 'A')
Expand All @@ -178,6 +187,7 @@ test "write_utf8_char" {
)
}

///|
test "write_utf16_char (alias for write_utf16le_char)" {
let buf = @buffer.new(size_hint=10)
@encoding.write_utf16_char(buf, 'A')
Expand All @@ -192,6 +202,7 @@ test "write_utf16_char (alias for write_utf16le_char)" {
)
}

///|
test "write_utf16le_char" {
let buf = @buffer.new(size_hint=10)
@encoding.write_utf16le_char(buf, 'A')
Expand All @@ -206,6 +217,7 @@ test "write_utf16le_char" {
)
}

///|
test "write_utf16be_char" {
let buf = @buffer.new(size_hint=10)
@encoding.write_utf16be_char(buf, 'A')
Expand Down
Loading
Loading