diff --git a/crypto/chacha.mbt b/crypto/chacha.mbt index 3a5fc45..a3a4ee1 100644 --- a/crypto/chacha.mbt +++ b/crypto/chacha.mbt @@ -21,6 +21,7 @@ fn flipWord(word : UInt) -> UInt { b0 | b1 | b2 | b3 } +///| test "flipWord" { let word = 0x12345678U let flipped = flipWord(word) @@ -52,6 +53,7 @@ fn quarterRound( state } +///| test "quarterRound" { let state = FixedArray::make(16, 0U) state[0] = 0x879531e0U @@ -90,6 +92,7 @@ fn chachaBlockRound(state : FixedArray[UInt]) -> FixedArray[UInt] { state8 } +///| test "chachaBlockRound" { let state = FixedArray::make(16, 0U) state[0] = 0x61707865U @@ -123,6 +126,7 @@ fn chachaBlockLoop(state : FixedArray[UInt], n : UInt) -> FixedArray[UInt] { } } +///| test "chachaBlockLoop" { let count = 1U let key = FixedArray::make(8, 0U) @@ -180,6 +184,7 @@ fn zipWith( result } +///| test "zipWith" { let state1 = FixedArray::make(4, 0U) state1[0] = 1 @@ -229,6 +234,7 @@ fn chachaBlock( flipState(combinedState) } +///| test "chachaBlock" { let key = FixedArray::make(8, 0U) key[0] = 0x00010203U @@ -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 diff --git a/crypto/chacha_test.mbt b/crypto/chacha_test.mbt index 7014e22..3295c66 100644 --- a/crypto/chacha_test.mbt +++ b/crypto/chacha_test.mbt @@ -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 diff --git a/crypto/md5.mbt b/crypto/md5.mbt index f49df44..a78453e 100644 --- a/crypto/md5.mbt +++ b/crypto/md5.mbt @@ -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(), @@ -244,6 +245,7 @@ test "md5_wb" { ) } +///| test { let ctx = MD5Context::new() md5_update(ctx, b"\x61".to_fixedarray()) diff --git a/crypto/md5_test.mbt b/crypto/md5_test.mbt index 3e984b1..41b5bf3 100644 --- a/crypto/md5_test.mbt +++ b/crypto/md5_test.mbt @@ -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") @@ -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.", diff --git a/crypto/sha1_test.mbt b/crypto/sha1_test.mbt index 3c9e00f..02313cd 100644 --- a/crypto/sha1_test.mbt +++ b/crypto/sha1_test.mbt @@ -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!( diff --git a/crypto/sha224.mbt b/crypto/sha224.mbt index e13d4df..a2cb286 100644 --- a/crypto/sha224.mbt +++ b/crypto/sha224.mbt @@ -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!( diff --git a/crypto/sha224_test.mbt b/crypto/sha224_test.mbt index d9ab9c4..e88a0fb 100644 --- a/crypto/sha224_test.mbt +++ b/crypto/sha224_test.mbt @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +///| test "sha224-additional" { assert_eq!( sha224test(""), diff --git a/crypto/sha256.mbt b/crypto/sha256.mbt index e51fda2..4382286 100644 --- a/crypto/sha256.mbt +++ b/crypto/sha256.mbt @@ -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] { diff --git a/crypto/sha256_test.mbt b/crypto/sha256_test.mbt index 97bc3d0..06a4e8a 100644 --- a/crypto/sha256_test.mbt +++ b/crypto/sha256_test.mbt @@ -23,6 +23,7 @@ fn sha224test(s : String) -> String { } // additional +///| test "sha256-additional" { assert_eq!( sha256test(""), diff --git a/crypto/sm3.mbt b/crypto/sm3.mbt index 92f485b..9b336ab 100644 --- a/crypto/sm3.mbt +++ b/crypto/sm3.mbt @@ -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() diff --git a/crypto/sm3_test.mbt b/crypto/sm3_test.mbt index 4548c6a..f344732 100644 --- a/crypto/sm3_test.mbt +++ b/crypto/sm3_test.mbt @@ -18,6 +18,7 @@ fn sm3test(s : String) -> String { } // additional +///| test "sm3-additional" { assert_eq!( sm3test(""), diff --git a/encoding/decoding_test.mbt b/encoding/decoding_test.mbt index 27d1b61..f7ebf3b 100644 --- a/encoding/decoding_test.mbt +++ b/encoding/decoding_test.mbt @@ -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()) @@ -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) @@ -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") @@ -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") @@ -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") @@ -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") @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/encoding/encoding_test.mbt b/encoding/encoding_test.mbt index 47bdb3a..f603fde 100644 --- a/encoding/encoding_test.mbt +++ b/encoding/encoding_test.mbt @@ -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) @@ -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) @@ -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) @@ -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) @@ -56,6 +60,7 @@ test "encoding String to UTF16BE" { ) } +///| test "to_utf8_bytes" { inspect!( @encoding.to_utf8_bytes('A'), @@ -83,6 +88,7 @@ test "to_utf8_bytes" { ) } +///| test "to_utf16_bytes (alias for to_utf16le_bytes)" { inspect!( @encoding.to_utf16_bytes('A'), @@ -110,6 +116,7 @@ test "to_utf16_bytes (alias for to_utf16le_bytes)" { ) } +///| test "to_utf16le_bytes" { inspect!( @encoding.to_utf16le_bytes('A'), @@ -137,6 +144,7 @@ test "to_utf16le_bytes" { ) } +///| test "to_utf16be_bytes" { inspect!( @encoding.to_utf16be_bytes('A'), @@ -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') @@ -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') @@ -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') @@ -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') diff --git a/fs/fs_test.mbt b/fs/fs_test.mbt index 17603d3..059da2d 100644 --- a/fs/fs_test.mbt +++ b/fs/fs_test.mbt @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +///| test "write_and_read" { let path = "1.txt" @fs.write_string_to_file( @@ -55,6 +56,7 @@ test "write_and_read" { } } +///| test "path_exist" { // dir exist assert_true!(@fs.path_exists(path=".github")) @@ -68,6 +70,7 @@ test "path_exist" { assert_false!(@fs.path_exists(path="no_exist.txt")) } +///| test "create_and_remove_dir" { @fs.create_dir(path="hello") assert_true!(@fs.path_exists(path="hello")) @@ -84,6 +87,7 @@ test "create_and_remove_dir" { } } +///| test "read_dir" { let dir_content = @fs.read_dir!(path="./fs")..sort() inspect!( diff --git a/json5/parse_error_test.mbt b/json5/parse_error_test.mbt index 5a110a0..29ddb84 100644 --- a/json5/parse_error_test.mbt +++ b/json5/parse_error_test.mbt @@ -13,46 +13,55 @@ // limitations under the License. //region errors +///| test "throws on empty documents" { let res = @json5.parse?("") inspect!(res, content="Err(Unexpected end of file)") } +///| test "throws on documents with only comments" { let res = @json5.parse?("//a") inspect!(res, content="Err(Unexpected end of file)") } +///| test "throws on incomplete single line comments" { let res = @json5.parse?("/a") inspect!(res, content="Err(Invalid character a at line 1, column 1)") } +///| test "throws on unterminated multiline comments" { let res = @json5.parse?("/*") inspect!(res, content="Err(Unexpected end of file)") } +///| test "throws on unterminated multiline comment closings" { let res = @json5.parse?("/**") inspect!(res, content="Err(Unexpected end of file)") } +///| test "throws on invalid characters in values" { let res = @json5.parse?("a") inspect!(res, content="Err(Invalid character a at line 1, column 0)") } +///| test "throws on invalid characters in identifier start escapes" { let res = @json5.parse?("{\\a:1}") inspect!(res, content="Err(Invalid character a at line 1, column 2)") } +///| test "throws on invalid characters in identifier continue escapes" { let res = @json5.parse?("{a\\a:1}") inspect!(res, content="Err(Invalid character a at line 1, column 3)") } +///| test "throws on invalid identifier continue characters" { let res = @json5.parse?("{a\\u0021:1}") inspect!( @@ -61,31 +70,37 @@ test "throws on invalid identifier continue characters" { ) } +///| test "throws on invalid characters following a sign" { let res = @json5.parse?("-a") inspect!(res, content="Err(Invalid character a at line 1, column 1)") } +///| test "throws on invalid characters following a leading decimal point" { let res = @json5.parse?(".a") inspect!(res, content="Err(Invalid character a at line 1, column 1)") } +///| test "throws on invalid characters following an exponent indicator" { let res = @json5.parse?("1ea") inspect!(res, content="Err(Invalid character a at line 1, column 2)") } +///| test "throws on invalid characters following an exponent sign" { let res = @json5.parse?("1e-a") inspect!(res, content="Err(Invalid character a at line 1, column 3)") } +///| test "throws on invalid characters following a hexadecimal indicator" { let res = @json5.parse?("0xg") inspect!(res, content="Err(Invalid character g at line 1, column 2)") } +///| test "throws on invalid new lines in strings" { let res = @json5.parse?("\"\n\"") inspect!( @@ -97,101 +112,121 @@ test "throws on invalid new lines in strings" { ) } +///| test "throws on unterminated strings" { let res = @json5.parse?("\"") inspect!(res, content="Err(Unexpected end of file)") } +///| test "throws on invalid identifier start characters in property names" { let res = @json5.parse?("{!:1}") inspect!(res, content="Err(Invalid character ! at line 1, column 1)") } +///| test "throws on invalid characters following a property name" { let res = @json5.parse?("{a!1}") inspect!(res, content="Err(Invalid character ! at line 1, column 2)") } +///| test "throws on invalid characters following a property value" { let res = @json5.parse?("{a:1!}") inspect!(res, content="Err(Invalid character ! at line 1, column 4)") } +///| test "throws on invalid characters following an array value" { let res = @json5.parse?("[1!]") inspect!(res, content="Err(Invalid character ! at line 1, column 2)") } +///| test "throws on invalid characters in literals" { let res = @json5.parse?("tru!") inspect!(res, content="Err(Invalid character ! at line 1, column 3)") } +///| test "throws on unterminated escapes" { let res = @json5.parse?("\"\\") inspect!(res, content="Err(Unexpected end of file)") } +///| test "throws on invalid first digits in hexadecimal escapes" { let res = @json5.parse?("\"\\xg\"") inspect!(res, content="Err(Invalid character g at line 1, column 3)") } +///| test "throws on invalid second digits in hexadecimal escapes" { let res = @json5.parse?("\"\\x0g\"") inspect!(res, content="Err(Invalid character g at line 1, column 4)") } +///| test "throws on invalid unicode escapes" { let res = @json5.parse?("\"\\u000g\"") inspect!(res, content="Err(Invalid character g at line 1, column 6)") } +///| test "throws on escaped digits" { let res = @json5.parse?("\"\\1\"") inspect!(res, content="Err(Invalid character 1 at line 1, column 2)") } +///| test "throws on octal escapes" { let res = @json5.parse?("\"\\01\"") inspect!(res, content="Err(Invalid character 1 at line 1, column 3)") } +///| test "throws on multiple values" { let res = @json5.parse?("1 2") inspect!(res, content="Err(Invalid character 2 at line 1, column 2)") } +///| test "throws with control characters escaped in the message" { let res = @json5.parse?("\x01") inspect!(res, content="Err(Invalid character \x01 at line 1, column 0)") } +///| test "throws on unclosed objects before property names" { let res = @json5.parse?("{") inspect!(res, content="Err(Unexpected end of file)") } +///| test "throws on unclosed objects after property names" { let res = @json5.parse?("{a") inspect!(res, content="Err(Unexpected end of file)") } +///| test "throws on unclosed objects before property values" { let res = @json5.parse?("{a:") inspect!(res, content="Err(Unexpected end of file)") } +///| test "throws on unclosed objects after property values" { let res = @json5.parse?("{a:1") inspect!(res, content="Err(Unexpected end of file)") } +///| test "throws on unclosed arrays before values" { let res = @json5.parse?("[") inspect!(res, content="Err(Unexpected end of file)") } +///| test "throws on unclosed arrays after values" { let res = @json5.parse?("[1") inspect!(res, content="Err(Unexpected end of file)") diff --git a/json5/parse_test.mbt b/json5/parse_test.mbt index 2346be6..58359d5 100644 --- a/json5/parse_test.mbt +++ b/json5/parse_test.mbt @@ -22,11 +22,13 @@ fn test_parse(input : String, loc~ : SourceLoc = _) -> @json.JsonValue!Error { } //region objects +///| test "parses empty objects" { let json = test_parse!("{}") assert_eq!(json, @json.JsonValue::Object(Map::of([]))) } +///| test "parses double string property names" { let json = test_parse!("{\"a\":1}") assert_eq!( @@ -35,6 +37,7 @@ test "parses double string property names" { ) } +///| test "parses single string property names" { let json = test_parse!("{a:1}") assert_eq!( @@ -43,6 +46,7 @@ test "parses single string property names" { ) } +///| test "parses unquoted property names" { let json = test_parse!("{a:1}") assert_eq!( @@ -51,6 +55,7 @@ test "parses unquoted property names" { ) } +///| test "parses special character property names" { let json = test_parse!("{$_:1,_$:2,a\u200C:3}") assert_eq!( @@ -65,6 +70,7 @@ test "parses special character property names" { ) } +///| test "parses unicode property names" { let json = test_parse!("{ùńîċõďë:9}") assert_eq!( @@ -75,6 +81,7 @@ test "parses unicode property names" { ) } +///| test "parses escaped property names" { let json = test_parse!("{\\u0061\\u0062:1,\\u0024\\u005F:2,\\u005F\\u0024:3}") assert_eq!( @@ -89,6 +96,7 @@ test "parses escaped property names" { ) } +///| test "preserves __proto__ property names" { let json = test_parse!("{\"__proto__\":1}") assert_eq!( @@ -99,6 +107,7 @@ test "preserves __proto__ property names" { ) } +///| test "parses multiple properties" { let json = test_parse!("{abc:1,def:2}") assert_eq!( @@ -112,6 +121,7 @@ test "parses multiple properties" { ) } +///| test "parses nested objects" { let json = test_parse!("{a:{b:2}}") assert_eq!( @@ -131,16 +141,19 @@ test "parses nested objects" { //endregion //region arrays +///| test "parses empty arrays" { let json = test_parse!("[]") assert_eq!(json, @json.JsonValue::Array([])) } +///| test "parses array values" { let json = test_parse!("[1]") assert_eq!(json, @json.JsonValue::Array([@json.JsonValue::Number(1.0)])) } +///| test "parses multiple array values" { let json = test_parse!("[1,2]") assert_eq!( @@ -152,6 +165,7 @@ test "parses multiple array values" { ) } +///| test "parses nested arrays" { let json = test_parse!("[1,[2,3]]") assert_eq!( @@ -168,6 +182,7 @@ test "parses nested arrays" { //endregion //region nulls +///| test "parses nulls" { let json = test_parse!("null") assert_eq!(json, @json.JsonValue::Null) @@ -175,11 +190,13 @@ test "parses nulls" { //endregion //region booleans +///| test "parses true" { let json = test_parse!("true") assert_eq!(json, @json.JsonValue::True) } +///| test "parses false" { let json = test_parse!("false") assert_eq!(json, @json.JsonValue::False) @@ -187,6 +204,7 @@ test "parses false" { //endregion //region numbers +///| test "parses leading zeroes" { let json = test_parse!("[0,0.,0e0]") assert_eq!( @@ -199,6 +217,7 @@ test "parses leading zeroes" { ) } +///| test "parses integers" { let json = test_parse!("[1,23,456,7890]") assert_eq!( @@ -212,6 +231,7 @@ test "parses integers" { ) } +///| test "parses signed numbers" { let json = test_parse!("[-1,+2,-.1,-0]") assert_eq!( @@ -225,6 +245,7 @@ test "parses signed numbers" { ) } +///| test "parses leading decimal points" { let json = test_parse!("[.1,.23]") assert_eq!( @@ -236,6 +257,7 @@ test "parses leading decimal points" { ) } +///| test "parses fractional numbers" { let json = test_parse!("[1.0,1.23]") assert_eq!( @@ -247,6 +269,7 @@ test "parses fractional numbers" { ) } +///| test "parses exponents" { let json = test_parse!("[1e0,1e1,1e01,1.e0,1.1e0,1e-1,1e+1]") assert_eq!( @@ -263,6 +286,7 @@ test "parses exponents" { ) } +///| test "parses hexadecimal numbers" { let json = test_parse!("[0x1,0x10,0xff,0xFF]") assert_eq!( @@ -276,6 +300,7 @@ test "parses hexadecimal numbers" { ) } +///| test "parses signed and unsigned Infinity" { let json = test_parse!("[Infinity,-Infinity]") assert_eq!( @@ -287,6 +312,7 @@ test "parses signed and unsigned Infinity" { ) } +///| test "parses NaN" { let json = test_parse!("NaN") let ok = match json { @@ -296,6 +322,7 @@ test "parses NaN" { assert_true!(ok) } +///| test "parses signed NaN" { let json = test_parse!("-NaN") let ok = match json { @@ -305,21 +332,25 @@ test "parses signed NaN" { assert_true!(ok) } +///| test "parses 1" { let json = test_parse!("1") assert_eq!(json, @json.JsonValue::Number(1.0)) } +///| test "parses +1.23e100" { let json = test_parse!("+1.23e100") assert_eq!(json, @json.JsonValue::Number(1.23e100)) } +///| test "parses bare hexadecimal number" { let json = test_parse!("0x1") assert_eq!(json, @json.JsonValue::Number(1.0)) } +///| test "parses bare long hexadecimal number" { let json = test_parse!("-0x0123456789abcdefABCDEF") assert_eq!(json, @json.JsonValue::Number(-0x0123456789abcdefABCDEF.0)) @@ -327,16 +358,19 @@ test "parses bare long hexadecimal number" { //endregion //region strings +///| test "parses double quoted strings" { let json = test_parse!("\"abc\"") assert_eq!(json, @json.JsonValue::String("abc")) } +///| test "parses single quoted strings" { let json = test_parse!("'abc'") assert_eq!(json, @json.JsonValue::String("abc")) } +///| test "parses quotes in strings" { let json = test_parse!("[\"\\\"\",\"'\"]") assert_eq!( @@ -348,6 +382,7 @@ test "parses quotes in strings" { ) } +///| test "parses escaped characters" { let json = test_parse!("'\\b\\f\\n\\r\\t\\v\\0\\x0f\\u01fF\\a\\'\\\"'") assert_eq!( @@ -362,16 +397,19 @@ test "parses escaped characters" { //endregion //region comments +///| test "parses single-line comments" { let json = test_parse!("{//comment\n}") assert_eq!(json, @json.JsonValue::Object(Map::of([]))) } +///| test "parses single-line comments at end of input" { let json = test_parse!("{}//comment") assert_eq!(json, @json.JsonValue::Object(Map::of([]))) } +///| test "parses multi-line comments" { let json = test_parse!("{/*comment\n** */}") assert_eq!(json, @json.JsonValue::Object(Map::of([]))) @@ -379,6 +417,7 @@ test "parses multi-line comments" { //endregion //region whitespace +///| test "parses whitespace" { let json = test_parse!("{\t\u000b\u000c \u00A0\uFEFF\n\r\u2028\u2029\u2003}") assert_eq!(json, @json.JsonValue::Object(Map::of([]))) diff --git a/stack/stack.mbt b/stack/stack.mbt index be0b291..eb4be28 100644 --- a/stack/stack.mbt +++ b/stack/stack.mbt @@ -24,6 +24,7 @@ pub fn Stack::new[T]() -> Stack[T] { { elements: Nil, len: 0 } } +///| test "new" { let s : Stack[Int] = Stack::new() inspect!(s, content="Stack::[]") @@ -41,6 +42,7 @@ pub fn Stack::from_list[T](list : @immut/list.T[T]) -> Stack[T] { { elements: list, len: list.length() } } +///| test "from_list" { let s = Stack::from_list(@immut/list.of([1, 2, 3])) inspect!(s, content="Stack::[1, 2, 3]") @@ -59,6 +61,7 @@ pub fn Stack::from_array[T](array : Array[T]) -> Stack[T] { { elements: @immut/list.from_array(array), len: array.length() } } +///| test "from_array" { let s = Stack::from_array([1, 2, 3]) inspect!(s, content="Stack::[1, 2, 3]") @@ -77,6 +80,7 @@ pub fn Stack::of[T](array : FixedArray[T]) -> Stack[T] { { elements: @immut/list.of(array), len: array.length() } } +///| test "of" { let s = Stack::of([1, 2, 3]) inspect!(s, content="Stack::[1, 2, 3]") @@ -100,6 +104,7 @@ pub fn output[T : Show](self : Stack[T], logger : &Logger) -> Unit { logger.write_string(self.to_string()) } +///| test "to_string" { let empty : Stack[Int] = Stack::new() inspect!(empty, content="Stack::[]") @@ -119,6 +124,7 @@ pub fn Stack::from_stack[T](other : Stack[T]) -> Stack[T] { { ..other } } +///| test "from_stack" { let s = Stack::of([1, 2, 3]) let s1 = Stack::from_stack(s) @@ -139,6 +145,7 @@ pub fn clear[T](self : Stack[T]) -> Unit { self.len = 0 } +///| test "clear" { let s = Stack::of([1, 2, 3]) s.clear() @@ -158,6 +165,7 @@ pub fn return_with_clear[T](self : Stack[T]) -> Stack[T] { self } +///| test "return_with_clear" { let s = Stack::of([1, 2, 3]).return_with_clear() inspect!(s, content="Stack::[]") @@ -177,6 +185,7 @@ pub fn push[T](self : Stack[T], x : T) -> Unit { self.len = self.len + 1 } +///| test "push" { let s = Stack::new() s.push(1) @@ -197,6 +206,7 @@ pub fn push_list[T](self : Stack[T], list : @immut/list.T[T]) -> Unit { list.each(fn(i) { self.push(i) }) } +///| test "push_list" { let s = Stack::new() s.push_list(@immut/list.of([1, 2, 3])) @@ -218,6 +228,7 @@ pub fn push_stack[T](self : Stack[T], stack : Stack[T]) -> Unit { stack.elements.each(fn(i) { self.push(i) }) } +///| test "push_stack" { let s = Stack::of([1, 2, 3]) let s1 : Stack[Int] = Stack::new() @@ -239,6 +250,7 @@ pub fn push_array[T](self : Stack[T], array : Array[T]) -> Unit { array.each(fn(i) { self.push(i) }) } +///| test "push_array" { let s : Stack[Int] = Stack::new() s.push_array([1, 2, 3]) @@ -269,6 +281,7 @@ pub fn pop[T](self : Stack[T]) -> T? { } } +///| test "pop" { let s = Stack::of([1, 2, 3]) let s1 : Stack[Int] = Stack::new() @@ -304,6 +317,7 @@ pub fn unsafe_pop[T](self : Stack[T]) -> T { } } +///| test "unsafe_pop" { let s = Stack::of([1, 2, 3]) inspect!(s.unsafe_pop(), content="1") @@ -331,6 +345,7 @@ pub fn drop[T](self : Stack[T]) -> Unit { } } +///| test "drop" { let s = Stack::of([1, 2, 3]) s.drop() @@ -358,6 +373,7 @@ pub fn drop_result[T](self : Stack[T]) -> Result[Unit, Unit] { } } +///| test "drop_result" { let s = Stack::of([1, 2, 3]) let s1 : Stack[Int] = Stack::new() @@ -384,6 +400,7 @@ pub fn peek[T](self : Stack[T]) -> T? { } } +///| test "peek" { let s = Stack::of([1, 2, 3]) inspect!(s.peek(), content="Some(1)") @@ -411,6 +428,7 @@ pub fn peek_exn[T](self : Stack[T]) -> T { } } +///| test "peek_exn" { let s : Stack[Int] = Stack::of([1, 2, 3]) inspect!(s.peek_exn(), content="1") @@ -430,6 +448,7 @@ pub fn is_empty[T](self : Stack[T]) -> Bool { self.len == 0 } +///| test "is_empty" { let empty : Stack[Unit] = Stack::new() inspect!(Stack::of([1, 2, 3]).is_empty(), content="false") @@ -452,6 +471,7 @@ pub fn each[T](self : Stack[T], f : (T) -> Unit) -> Unit { self.elements.each(f) } +///| test "iter" { let s : Stack[Int] = Stack::new() let mut sum = 0 @@ -482,6 +502,7 @@ pub fn fold[T, U](self : Stack[T], init~ : U, f : (U, T) -> U) -> U { self.elements.fold(init~, f) } +///| test "fold" { let s = Stack::of([1, 2, 3]) let sum = s.fold(init=0, fn(acc, i) { acc + i }) @@ -499,6 +520,7 @@ pub fn to_list[T](self : Stack[T]) -> @immut/list.T[T] { self.elements } +///| test "to_list" { inspect!(Stack::of([3, 2, 1]).to_list(), content="@list.of([3, 2, 1])") } @@ -514,6 +536,7 @@ pub fn to_array[T : Default](self : Stack[T]) -> Array[T] { self.elements.to_array() } +///| test "to_array" { inspect!(Stack::of([3, 2, 1]).to_array(), content="[3, 2, 1]") } @@ -541,6 +564,7 @@ pub fn op_equal[T : Eq](self : Stack[T], other : Stack[T]) -> Bool { self.equal(other) } +///| test "equal" { inspect!(Stack::of([2, 4, 6]).equal(Stack::of([2, 4, 6])), content="true") inspect!(Stack::of([2, 4, 6]).equal(Stack::of([2, 4, 7])), content="false") diff --git a/sys/sys_test.mbt b/sys/sys_test.mbt index 964dcb7..3e3ec59 100644 --- a/sys/sys_test.mbt +++ b/sys/sys_test.mbt @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +///| test "get_env_vars" { let (k, v) = ("THIS_IS_A_TEST_FOR_ENV_VAR", "IT_WORKS") inspect!( diff --git a/time/duration_test.mbt b/time/duration_test.mbt index 65286fd..67da23f 100644 --- a/time/duration_test.mbt +++ b/time/duration_test.mbt @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +///| test "from_string" { inspect!(@time.Duration::from_string!("PT0S"), content="PT0S") inspect!( @@ -27,6 +28,7 @@ test "from_string" { assert_true!(@time.Duration::from_string?("P1Y2M3DT4H5M6S").is_err()) } +///| test "getters" { let d = @time.Duration::of!( hours=1L, @@ -38,6 +40,7 @@ test "getters" { inspect!(d.nanoseconds(), content="400") } +///| test "is_zero" { inspect!(@time.Duration::zero().is_zero(), content="true") inspect!(@time.Duration::of!().is_zero(), content="true") @@ -47,6 +50,7 @@ test "is_zero" { inspect!(@time.Duration::of!(nanoseconds=1L).is_zero(), content="false") } +///| test "is_neg" { inspect!(@time.Duration::zero().is_neg(), content="false") inspect!(@time.Duration::of!(seconds=1L).is_neg(), content="false") @@ -58,6 +62,7 @@ test "is_neg" { inspect!(@time.Duration::of!(nanoseconds=1L).is_neg(), content="false") } +///| test "add_seconds" { inspect!(@time.Duration::zero().add_seconds!(0L), content="PT0S") inspect!(@time.Duration::zero().add_seconds!(1L), content="PT1S") @@ -78,12 +83,14 @@ test "add_seconds" { ) } +///| test "with_seconds" { let d = @time.Duration::of!(seconds=20L) inspect!(d.with_seconds(20L), content="PT20S") inspect!(d.with_seconds(30L), content="PT30S") } +///| test "with_nanoseconds" { let d = @time.Duration::of!(nanoseconds=1000L) inspect!(d.with_nanoseconds!(1000), content="PT0.000001S") diff --git a/time/duration_wbtest.mbt b/time/duration_wbtest.mbt index 41c0a0f..c5b6aaf 100644 --- a/time/duration_wbtest.mbt +++ b/time/duration_wbtest.mbt @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +///| test "of" { inspect!( Duration::of!(hours=1L, minutes=2L, seconds=3L, nanoseconds=456789L), @@ -36,6 +37,7 @@ test "of" { inspect!(Duration::of!(nanoseconds=-200L), content="PT-0.0000002S") } +///| test "add_hours" { inspect!(Duration::zero().add_hours!(0L), content="PT0S") inspect!(Duration::zero().add_hours!(1L), content="PT1H") @@ -52,6 +54,7 @@ test "add_hours" { assert_true!(Duration::zero().add_hours?(@int64.min_value).is_err()) } +///| test "add_minutes" { inspect!(Duration::zero().add_minutes!(0L), content="PT0S") inspect!(Duration::zero().add_minutes!(1L), content="PT1M") @@ -68,6 +71,7 @@ test "add_minutes" { assert_true!(Duration::zero().add_minutes?(@int64.min_value).is_err()) } +///| test "add_nanoseconds" { inspect!(Duration::zero().add_nanoseconds!(0L), content="PT0S") inspect!(Duration::zero().add_nanoseconds!(1L), content="PT0.000000001S") @@ -116,6 +120,7 @@ test "add_nanoseconds" { ) } +///| test "op_add" { let p1 = Duration::of!(hours=1L, minutes=1L, seconds=1L, nanoseconds=1000L) let p2 = Duration::of!( diff --git a/time/period_test.mbt b/time/period_test.mbt index cead33a..92337e7 100644 --- a/time/period_test.mbt +++ b/time/period_test.mbt @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +///| test "of" { inspect!( @time.Period::of(years=1000, months=24, days=365), @@ -19,6 +20,7 @@ test "of" { ) } +///| test "from_string" { inspect!(@time.Period::from_string!("P10Y2M3D"), content="P10Y2M3D") inspect!(@time.Period::from_string!("P-10Y-2M-3D"), content="P-10Y-2M-3D") @@ -29,6 +31,7 @@ test "from_string" { assert_true!(@time.Period::from_string?("P2.5Y").is_err()) } +///| test "getters" { let p = @time.Period::of(years=1, months=2, days=3) inspect!(p.years(), content="1") @@ -37,6 +40,7 @@ test "getters" { inspect!(p.to_total_months(), content="14") } +///| test "is_zero" { inspect!(@time.Period::zero().is_zero(), content="true") inspect!(@time.Period::of().is_zero(), content="true") @@ -45,12 +49,14 @@ test "is_zero" { inspect!(@time.Period::of(days=1).is_zero(), content="false") } +///| test "is_neg" { inspect!(@time.Period::of().is_neg(), content="false") inspect!(@time.Period::of(years=1, months=1).is_neg(), content="false") inspect!(@time.Period::of(years=-1, months=1).is_neg(), content="true") } +///| test "add_years" { let p = @time.Period::of(years=10) inspect!(p.add_years!(0), content="P10Y") @@ -58,6 +64,7 @@ test "add_years" { inspect!(p.add_years!(-1), content="P9Y") } +///| test "add_months" { let p = @time.Period::of(months=10) inspect!(p.add_months!(0), content="P10M") @@ -65,6 +72,7 @@ test "add_months" { inspect!(p.add_months!(-1), content="P9M") } +///| test "add_weeks" { let p = @time.Period::of(days=10) inspect!(p.add_weeks!(0), content="P10D") @@ -72,6 +80,7 @@ test "add_weeks" { inspect!(p.add_weeks!(-1), content="P3D") } +///| test "add_days" { let p = @time.Period::of(days=10) inspect!(p.add_days!(0), content="P10D") @@ -79,24 +88,28 @@ test "add_days" { inspect!(p.add_days!(-1), content="P9D") } +///| test "with_years" { inspect!(@time.Period::of(years=1).with_years(1), content="P1Y") inspect!(@time.Period::of(years=1).with_years(2), content="P2Y") inspect!(@time.Period::of(years=1).with_years(-1), content="P-1Y") } +///| test "with_months" { inspect!(@time.Period::of(months=1).with_months(1), content="P1M") inspect!(@time.Period::of(months=1).with_months(2), content="P2M") inspect!(@time.Period::of(months=1).with_months(-1), content="P-1M") } +///| test "with_days" { inspect!(@time.Period::of(days=1).with_days(1), content="P1D") inspect!(@time.Period::of(days=1).with_days(2), content="P2D") inspect!(@time.Period::of(days=1).with_days(-1), content="P-1D") } +///| test "op_add" { let p1 = @time.Period::of(years=1, months=2, days=3) let p2 = @time.Period::of(years=-1, months=-2, days=-3) @@ -118,6 +131,7 @@ test "op_add" { assert_true!(p2.op_add?(p4).is_err()) } +///| test "op_sub" { let p1 = @time.Period::of(years=1, months=2, days=3) let p2 = @time.Period::of(years=-1, months=-2, days=-3) @@ -138,6 +152,7 @@ test "op_sub" { assert_true!(p4.op_sub?(p1).is_err()) } +///| test "multiply" { let p = @time.Period::of(years=1, months=2, days=3) inspect!(p.multiply!(0), content="P0D") @@ -148,6 +163,7 @@ test "multiply" { assert_true!(p.multiply?(@int.min_value).is_err()) } +///| test "negated" { let p = @time.Period::of(years=1, months=1, days=1) inspect!(p.negated!(), content="P-1Y-1M-1D") diff --git a/time/plain_date_test.mbt b/time/plain_date_test.mbt index 90af9d0..6a5ca5f 100644 --- a/time/plain_date_test.mbt +++ b/time/plain_date_test.mbt @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +///| test "of" { inspect!(@time.PlainDate::of!(0, 1, 1), content="0000-01-01") inspect!(@time.PlainDate::of!(1, 1, 1), content="0001-01-01") @@ -25,6 +26,7 @@ test "of" { assert_true!(@time.PlainDate::of?(10000, 1, 1).is_err()) } +///| test "from_year_ord" { inspect!(@time.PlainDate::from_year_ord!(0, 1), content="0000-01-01") inspect!(@time.PlainDate::from_year_ord!(1, 365), content="0001-12-31") @@ -39,6 +41,7 @@ test "from_year_ord" { assert_true!(@time.PlainDate::from_year_ord?(-10000, 365).is_err()) } +///| test "from_string" { inspect!(@time.PlainDate::from_string!("9999-01-01"), content="9999-01-01") inspect!(@time.PlainDate::from_string!("0000-01-01"), content="0000-01-01") @@ -51,6 +54,7 @@ test "from_string" { assert_true!(@time.PlainDate::from_string?("-01").is_err()) } +///| test "compare" { inspect!( @time.PlainDate::of!(2000, 1, 1) == @time.PlainDate::of!(2000, 1, 1), @@ -82,6 +86,7 @@ test "compare" { ) } +///| test "era" { inspect!(@time.PlainDate::of!(-9999, 1, 1).era(), content="BCE") inspect!(@time.PlainDate::of!(-1, 1, 1).era(), content="BCE") @@ -90,6 +95,7 @@ test "era" { inspect!(@time.PlainDate::of!(9999, 1, 1).era(), content="CE") } +///| test "era_year" { inspect!(@time.PlainDate::of!(-9999, 1, 1).era_year(), content="10000") inspect!(@time.PlainDate::of!(-1, 1, 1).era_year(), content="2") @@ -98,6 +104,7 @@ test "era_year" { inspect!(@time.PlainDate::of!(9999, 1, 1).era_year(), content="9999") } +///| test "getters" { let date = @time.PlainDate::of!(2000, 12, 31) inspect!(date.year(), content="2000") @@ -111,6 +118,7 @@ test "getters" { inspect!(date.ordinal(), content="366") } +///| test "weekday" { inspect!(@time.PlainDate::of!(2000, 1, 1).weekday(), content="Saturday") inspect!(@time.PlainDate::of!(2000, 1, 2).weekday(), content="Sunday") @@ -121,16 +129,19 @@ test "weekday" { inspect!(@time.PlainDate::of!(2000, 1, 7).weekday(), content="Friday") } +///| test "ordinal" { inspect!(@time.PlainDate::of!(1, 1, 1).ordinal(), content="1") inspect!(@time.PlainDate::of!(2000, 12, 31).ordinal(), content="366") inspect!(@time.PlainDate::of!(2001, 12, 31).ordinal(), content="365") } +///| test "days_in_week" { inspect!(@time.PlainDate::of!(1, 1, 1).days_in_week(), content="7") } +///| test "days_in_month" { inspect!(@time.PlainDate::of!(2000, 1, 1).days_in_month(), content="31") inspect!(@time.PlainDate::of!(2000, 2, 1).days_in_month(), content="29") @@ -147,6 +158,7 @@ test "days_in_month" { inspect!(@time.PlainDate::of!(2001, 2, 1).days_in_month(), content="28") } +///| test "days_in_year" { inspect!(@time.PlainDate::of!(2000, 1, 1).days_in_year(), content="366") inspect!(@time.PlainDate::of!(2001, 1, 1).days_in_year(), content="365") @@ -154,10 +166,12 @@ test "days_in_year" { inspect!(@time.PlainDate::of!(-2001, 1, 1).days_in_year(), content="365") } +///| test "months_in_year" { inspect!(@time.PlainDate::of!(2000, 1, 1).months_in_year(), content="12") } +///| test "in_leap_year" { inspect!(@time.PlainDate::of!(2000, 1, 1).in_leap_year(), content="true") inspect!(@time.PlainDate::of!(2000, 1, 1).in_leap_year(), content="true") @@ -169,6 +183,7 @@ test "in_leap_year" { inspect!(@time.PlainDate::of!(1, 1, 1).in_leap_year(), content="false") } +///| test "add_years" { let d = @time.PlainDate::of!(2000, 2, 29) inspect!(d.add_years!(0L), content="2000-02-29") @@ -183,6 +198,7 @@ test "add_years" { inspect!(d.add_years!(@int64.min_value), content="2000-02-29") } +///| test "add_months" { let d = @time.PlainDate::of!(2000, 2, 29) inspect!(d.add_months!(0L), content="2000-02-29") @@ -208,6 +224,7 @@ test "add_months" { assert_true!(d.add_months?(@int64.min_value).is_err()) } +///| test "add_weeks" { let d = @time.PlainDate::of!(2000, 2, 29) inspect!(d.add_weeks!(0L), content="2000-02-29") @@ -227,6 +244,7 @@ test "add_weeks" { assert_true!(d.add_weeks?(@int64.min_value).is_err()) } +///| test "add_days" { let d = @time.PlainDate::of!(2000, 2, 29) inspect!(d.add_days!(0L), content="2000-02-29") @@ -246,6 +264,7 @@ test "add_days" { assert_true!(d.add_days?(@int64.min_value).is_err()) } +///| test "add_period" { let d = @time.PlainDate::of!(2000, 2, 29) inspect!(d.add_period!(@time.Period::of(years=1)), content="2001-02-28") @@ -257,6 +276,7 @@ test "add_period" { ) } +///| test "with_year" { let d = @time.PlainDate::of!(2000, 2, 29) inspect!(d.with_year!(2000), content="2000-02-29") @@ -269,6 +289,7 @@ test "with_year" { assert_true!(d.with_year?(-10000).is_err()) } +///| test "with_month" { let d = @time.PlainDate::of!(2000, 1, 31) inspect!(d.with_month!(1), content="2000-01-31") @@ -278,6 +299,7 @@ test "with_month" { assert_true!(d.with_month?(13).is_err()) } +///| test "with_day" { let d = @time.PlainDate::of!(2000, 2, 29) inspect!(d.with_day!(29), content="2000-02-29") @@ -286,6 +308,7 @@ test "with_day" { assert_true!(d.with_day?(30).is_err()) } +///| test "with_ordinal" { let d = @time.PlainDate::of!(2000, 2, 29) inspect!(d.with_ordinal!(1), content="2000-01-01") @@ -294,6 +317,7 @@ test "with_ordinal" { assert_true!(d.with_ordinal?(367).is_err()) } +///| test "until" { inspect!( @time.PlainDate::of!(1970, 1, 1).until!(@time.PlainDate::of!(2000, 1, 1)), @@ -325,6 +349,7 @@ test "until" { ) } +///| test "until and add_period" { let start = @time.PlainDate::of!(2000, 1, 1) let p = start.until!(@time.PlainDate::of!(2024, 1, 1)) diff --git a/time/plain_date_time_test.mbt b/time/plain_date_time_test.mbt index 9b35d51..50a70f4 100644 --- a/time/plain_date_time_test.mbt +++ b/time/plain_date_time_test.mbt @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +///| test "of" { inspect!(@time.PlainDateTime::of!(2000, 1, 1), content="2000-01-01T00:00:00") inspect!( @@ -53,6 +54,7 @@ test "of" { ) } +///| test "from_unix_second" { inspect!( @time.PlainDateTime::from_unix_second!(1714227729L, 1000, @time.utc_offset), @@ -73,6 +75,7 @@ test "from_unix_second" { ) } +///| test "from_string" { inspect!( @time.PlainDateTime::from_string!("0000-01-01T00:00:00"), @@ -103,6 +106,7 @@ test "from_string" { assert_true!(@time.PlainDateTime::from_string?("00:00:00").is_err()) } +///| test "getters" { let d = @time.PlainDateTime::of!( 2000, @@ -130,11 +134,13 @@ test "getters" { inspect!(d.nanosecond(), content="1000") } +///| test "in_leap_year" { inspect!(@time.PlainDateTime::of!(2000, 1, 1).in_leap_year(), content="true") inspect!(@time.PlainDateTime::of!(2001, 1, 1).in_leap_year(), content="false") } +///| test "add_years" { let d = @time.PlainDateTime::of!(2000, 2, 29) inspect!(d.add_years!(0L), content="2000-02-29T00:00:00") @@ -145,6 +151,7 @@ test "add_years" { assert_true!(d.add_years?(-12000L).is_err()) } +///| test "add_months" { let d = @time.PlainDateTime::of!(2000, 2, 29) inspect!(d.add_months!(0L), content="2000-02-29T00:00:00") @@ -155,6 +162,7 @@ test "add_months" { assert_true!(d.add_months?(12L * -12000L).is_err()) } +///| test "add_weeks" { let d = @time.PlainDateTime::of!(2000, 2, 29) inspect!(d.add_weeks!(0L), content="2000-02-29T00:00:00") @@ -166,6 +174,7 @@ test "add_weeks" { assert_true!(d.add_weeks?(@int64.min_value).is_err()) } +///| test "add_days" { let d = @time.PlainDateTime::of!(2000, 2, 29) inspect!(d.add_days!(0L), content="2000-02-29T00:00:00") @@ -177,6 +186,7 @@ test "add_days" { assert_true!(d.add_days?(@int64.min_value).is_err()) } +///| test "add_period" { let d = @time.PlainDateTime::of!(2000, 2, 29) inspect!( @@ -197,6 +207,7 @@ test "add_period" { ) } +///| test "add_hours" { let d = @time.PlainDateTime::of!(0, 1, 1) inspect!(d.add_hours!(0L), content="0000-01-01T00:00:00") @@ -206,6 +217,7 @@ test "add_hours" { inspect!(d.add_hours!(24L * 366L), content="0001-01-01T00:00:00") } +///| test "add_minutes" { let d = @time.PlainDateTime::of!(0, 1, 1) inspect!(d.add_minutes!(0L), content="0000-01-01T00:00:00") @@ -215,6 +227,7 @@ test "add_minutes" { inspect!(d.add_minutes!(24L * 60L * 366L), content="0001-01-01T00:00:00") } +///| test "add_seconds" { let d = @time.PlainDateTime::of!(0, 1, 1) inspect!(d.add_seconds!(0L), content="0000-01-01T00:00:00") @@ -228,6 +241,7 @@ test "add_seconds" { ) } +///| test "add_duration" { let d = @time.PlainDateTime::of!(0, 1, 1) inspect!( @@ -258,6 +272,7 @@ test "add_duration" { ) } +///| test "with_year" { let d = @time.PlainDateTime::of!(2000, 2, 29) inspect!(d.with_year!(2000), content="2000-02-29T00:00:00") @@ -270,6 +285,7 @@ test "with_year" { assert_true!(d.with_year?(-10000).is_err()) } +///| test "with_month" { let d = @time.PlainDateTime::of!(2000, 1, 31) inspect!(d.with_month!(1), content="2000-01-31T00:00:00") @@ -279,6 +295,7 @@ test "with_month" { assert_true!(d.with_month?(13).is_err()) } +///| test "with_day" { let d = @time.PlainDateTime::of!(2000, 2, 29) inspect!(d.with_day!(29), content="2000-02-29T00:00:00") @@ -287,6 +304,7 @@ test "with_day" { assert_true!(d.with_day?(30).is_err()) } +///| test "with_ordinal" { let d = @time.PlainDateTime::of!(2000, 2, 29) inspect!(d.with_ordinal!(1), content="2000-01-01T00:00:00") @@ -295,6 +313,7 @@ test "with_ordinal" { assert_true!(d.with_ordinal?(367).is_err()) } +///| test "with_hour" { let d = @time.PlainDateTime::of!(2000, 1, 1, hour=1) inspect!(d.with_hour!(1), content="2000-01-01T01:00:00") @@ -305,6 +324,7 @@ test "with_hour" { assert_true!(d.with_hour?(25).is_err()) } +///| test "with_minute" { let d = @time.PlainDateTime::of!(2000, 1, 1, minute=20) inspect!(d.with_minute!(20), content="2000-01-01T00:20:00") @@ -315,6 +335,7 @@ test "with_minute" { assert_true!(d.with_minute?(60).is_err()) } +///| test "with_second" { let d = @time.PlainDateTime::of!(2000, 1, 1, second=30) inspect!(d.with_second!(30), content="2000-01-01T00:00:30") @@ -325,6 +346,7 @@ test "with_second" { assert_true!(d.with_second?(60).is_err()) } +///| test "with_nanosecond" { let d = @time.PlainDateTime::of!(2000, 1, 1, nanosecond=400) inspect!(d.with_nanosecond!(400), content="2000-01-01T00:00:00.0000004") @@ -338,6 +360,7 @@ test "with_nanosecond" { assert_true!(d.with_nanosecond?(1_000_000_000).is_err()) } +///| test "to_plain_date and to_plain_time" { let d = @time.PlainDateTime::of!( 2000, diff --git a/time/plain_date_time_wbtest.mbt b/time/plain_date_time_wbtest.mbt index fb72d5e..7c36e88 100644 --- a/time/plain_date_time_wbtest.mbt +++ b/time/plain_date_time_wbtest.mbt @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +///| test "add_nanoseconds!" { let d = PlainDateTime::of!(0, 1, 1) inspect!(d.add_nanoseconds!(0L), content="0000-01-01T00:00:00") diff --git a/time/plain_date_wbtest.mbt b/time/plain_date_wbtest.mbt index 0f4a142..3946114 100644 --- a/time/plain_date_wbtest.mbt +++ b/time/plain_date_wbtest.mbt @@ -12,11 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. +///| test "create_from_valid" { inspect!(create_from_valid(2001, 2, 29), content="2001-02-28") inspect!(create_from_valid(-2001, 2, 29), content="-2001-02-28") } +///| test "date_to_fixed_days" { inspect!(date_to_fixed_days(0, 1, 1), content="0") inspect!(date_to_fixed_days(1, 1, 1), content="366") @@ -26,6 +28,7 @@ test "date_to_fixed_days" { inspect!(date_to_fixed_days(1970, 1, 1), content="719528") } +///| test "fixed_days_to_year_ord" { inspect!(fixed_days_to_year_ord(0L), content="(0, 1)") inspect!(fixed_days_to_year_ord(1L), content="(0, 2)") diff --git a/time/plain_time_test.mbt b/time/plain_time_test.mbt index 8fef7f9..c34282f 100644 --- a/time/plain_time_test.mbt +++ b/time/plain_time_test.mbt @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +///| test "of" { inspect!(@time.PlainTime::of!(0, 0, 0, 0), content="00:00:00") inspect!(@time.PlainTime::of!(24, 0, 0, 0), content="24:00:00") @@ -23,6 +24,7 @@ test "of" { assert_true!(@time.PlainTime::of?(-1, 0, 0, 0).is_err()) } +///| test "from_string" { inspect!(@time.PlainTime::from_string!("00:00"), content="00:00:00") inspect!(@time.PlainTime::from_string!("23:59"), content="23:59:00") @@ -44,6 +46,7 @@ test "from_string" { assert_true!(@time.PlainTime::from_string?("z1:00:00").is_err()) } +///| test "getters" { let time = @time.PlainTime::of!(1, 2, 3, 400) inspect!(time.hour(), content="1") @@ -52,12 +55,14 @@ test "getters" { inspect!(time.nanosecond(), content="400") } +///| test "second_of_day" { inspect!(@time.PlainTime::of!(0, 0, 0, 0).second_of_day(), content="0") inspect!(@time.PlainTime::of!(12, 30, 30, 0).second_of_day(), content="45030") inspect!(@time.PlainTime::of!(24, 0, 0, 0).second_of_day(), content="86400") } +///| test "nanosecond_of_day" { inspect!(@time.PlainTime::of!(0, 0, 0, 0).nanosecond_of_day(), content="0") inspect!( @@ -70,6 +75,7 @@ test "nanosecond_of_day" { ) } +///| test "from_second_of_day" { inspect!(@time.PlainTime::from_second_of_day!(0), content="00:00:00") inspect!(@time.PlainTime::from_second_of_day!(86400), content="24:00:00") @@ -79,6 +85,7 @@ test "from_second_of_day" { assert_true!(@time.PlainTime::from_second_of_day?(86401).is_err()) } +///| test "from_nanosecond_of_day" { inspect!(@time.PlainTime::from_nanosecond_of_day!(0L), content="00:00:00") inspect!( @@ -95,6 +102,7 @@ test "from_nanosecond_of_day" { ) } +///| test "add_hours" { let time = @time.PlainTime::of!(10, 0, 0, 0) inspect!(time.add_hours!(-1L), content="09:00:00") @@ -122,6 +130,7 @@ test "add_hours" { inspect!(time.add_hours!(@int64.max_value), content="17:00:00") } +///| test "add_minutes" { let time = @time.PlainTime::of!(0, 30, 0, 0) inspect!(time.add_minutes!(-1L), content="00:29:00") @@ -138,6 +147,7 @@ test "add_minutes" { inspect!(time.add_minutes!(@int64.max_value), content="18:37:00") } +///| test "add_seconds" { let time = @time.PlainTime::of!(0, 0, 30, 0) inspect!(time.add_seconds!(-1L), content="00:00:29") @@ -151,6 +161,7 @@ test "add_seconds" { inspect!(time.add_seconds!(24L * 60L * 60L), content="00:00:30") } +///| test "with_hour" { inspect!( @time.PlainTime::of!(1, 20, 30, 400).with_hour!(1), @@ -169,6 +180,7 @@ test "with_hour" { assert_true!(@time.PlainTime::of!(1, 20, 30, 400).with_hour?(25).is_err()) } +///| test "with_minute" { inspect!( @time.PlainTime::of!(1, 20, 30, 400).with_minute!(20), @@ -190,6 +202,7 @@ test "with_minute" { assert_true!(@time.PlainTime::of!(1, 20, 30, 400).with_minute?(60).is_err()) } +///| test "with_second" { inspect!( @time.PlainTime::of!(1, 20, 30, 400).with_second!(30), @@ -211,6 +224,7 @@ test "with_second" { assert_true!(@time.PlainTime::of!(1, 20, 30, 400).with_second?(60).is_err()) } +///| test "with_nanosecond" { inspect!( @time.PlainTime::of!(1, 20, 30, 400).with_nanosecond!(400), @@ -238,6 +252,7 @@ test "with_nanosecond" { ) } +///| test "until" { let time = @time.PlainTime::of!(12, 0, 0, 0) inspect!( diff --git a/time/plain_time_wbtest.mbt b/time/plain_time_wbtest.mbt index 59ae05c..5b9358b 100644 --- a/time/plain_time_wbtest.mbt +++ b/time/plain_time_wbtest.mbt @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +///| test "validate_time" { inspect!(validate_time(1, 0, 0, 0), content="true") inspect!(validate_time(0, 0, 0, 0), content="true") @@ -25,6 +26,7 @@ test "validate_time" { inspect!(validate_time(1, 0, 0, 1_000_000_000), content="false") } +///| test "add_nanoseconds" { let time = PlainTime::of!(0, 0, 00, 1000) inspect!(time.add_nanoseconds!(-1L), content="00:00:00.000000999") @@ -45,6 +47,7 @@ test "add_nanoseconds" { ) } +///| test "add_duration" { let time = PlainTime::of!(12, 0, 0, 0) inspect!( @@ -62,6 +65,7 @@ test "add_duration" { inspect!(time.add_duration!(Duration::zero()), content="12:00:00") } +///| test "at_date" { let time = PlainTime::of!(12, 0, 0, 0) let date = PlainDate::of!(2000, 1, 1) diff --git a/time/util.mbt b/time/util.mbt index 197b7ce..2ef9927 100644 --- a/time/util.mbt +++ b/time/util.mbt @@ -38,6 +38,7 @@ fn remove_prefix_zero(s : String) -> String { } } +///| test "add_prefix_zero" { inspect!(add_prefix_zero("", 2), content="00") inspect!(add_prefix_zero("1", 0), content="1") @@ -46,6 +47,7 @@ test "add_prefix_zero" { inspect!(add_prefix_zero("1", 3), content="001") } +///| test "remove_prefix_zero" { inspect!(remove_prefix_zero(""), content="") inspect!(remove_prefix_zero("01"), content="1") @@ -75,6 +77,7 @@ fn remove_suffix_zero(s : String) -> String { s.substring(end=i + 1) } +///| test "add_suffix_zero" { inspect!(add_suffix_zero("1", 0), content="1") inspect!(add_suffix_zero("1", 1), content="1") @@ -82,6 +85,7 @@ test "add_suffix_zero" { inspect!(add_suffix_zero("1", 3), content="100") } +///| test "remove_suffix_zero" { inspect!(remove_suffix_zero(""), content="") inspect!(remove_suffix_zero("1000100"), content="10001") @@ -107,6 +111,7 @@ fn split(s : String, delimiter : Char) -> Array[String] { spl } +///| test "split" { inspect!( split("2000-01-01", '-'), @@ -203,6 +208,7 @@ fn checked_mul_int64(x : Int64, y : Int64) -> Int64!Error { r } +///| test "checked_add_int" { inspect!(checked_add_int?(1, 1), content="Ok(2)") inspect!(checked_add_int?(1, -1), content="Ok(0)") @@ -221,6 +227,7 @@ test "checked_add_int" { ) } +///| test "checked_mul_int" { inspect!(checked_mul_int?(2, 3), content="Ok(6)") inspect!(checked_mul_int?(2, -3), content="Ok(-6)") @@ -239,6 +246,7 @@ test "checked_mul_int" { ) } +///| test "checked_add_int64" { inspect!(checked_add_int64?(1L, 1L), content="Ok(2)") inspect!(checked_add_int64?(1L, -1L), content="Ok(0)") @@ -257,6 +265,7 @@ test "checked_add_int64" { ) } +///| test "checked_mul_int64" { inspect!(checked_mul_int64?(2L, 3L), content="Ok(6)") inspect!(checked_mul_int64?(2L, -3L), content="Ok(-6)") @@ -298,6 +307,7 @@ fn floor_div_int(x : Int, y : Int) -> Int!Error { floor(r).to_int() } +///| test "floor_div_int" { inspect!(floor_div_int?(1, 10), content="Ok(0)") inspect!(floor_div_int?(-1, 10), content="Ok(-1)") @@ -321,6 +331,7 @@ fn floor_div_int64(x : Int64, y : Int64) -> Int64!Error { floor(r).to_int64() } +///| test "floor_div_int64" { inspect!(floor_div_int64?(1L, 10L), content="Ok(0)") inspect!(floor_div_int64?(-1L, 10L), content="Ok(-1)") @@ -335,6 +346,7 @@ fn floor_mod_int(x : Int, y : Int) -> Int!Error { x - floor_div_int!(x, y) * y } +///| test "floor_mod_int" { inspect!(floor_mod_int?(1, 10), content="Ok(1)") inspect!(floor_mod_int?(-1, 10), content="Ok(9)") @@ -354,6 +366,7 @@ fn floor_mod_int64(x : Int64, y : Int64) -> Int64!Error { x - floor_div_int64!(x, y) * y } +///| test "floor_mod_int64" { inspect!(floor_mod_int64?(1L, 10L), content="Ok(1)") inspect!(floor_mod_int64?(-1L, 10L), content="Ok(9)") diff --git a/time/weekday.mbt b/time/weekday.mbt index 99dc00d..c4db641 100644 --- a/time/weekday.mbt +++ b/time/weekday.mbt @@ -50,6 +50,7 @@ fn value(self : Weekday) -> Int { } } +///| test "new" { inspect!(Weekday::new(0), content="None") inspect!(Weekday::new(1), content="Some(Monday)") @@ -62,6 +63,7 @@ test "new" { inspect!(Weekday::new(8), content="None") } +///| test "value" { inspect!(Weekday::Monday.value(), content="1") inspect!(Weekday::Tuesday.value(), content="2") diff --git a/time/zone.mbt b/time/zone.mbt index 5748f91..4252b1c 100644 --- a/time/zone.mbt +++ b/time/zone.mbt @@ -133,6 +133,7 @@ fn ascii_to_string(b : FixedArray[Byte], start : Int) -> String { result.to_string() } +///| test "Zone::from_tzif2" { let data : FixedArray[Byte] = [ // magic number diff --git a/time/zone_offset_test.mbt b/time/zone_offset_test.mbt index 20b27fe..b0672cd 100644 --- a/time/zone_offset_test.mbt +++ b/time/zone_offset_test.mbt @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +///| test "of" { inspect!(@time.ZoneOffset::of!(), content="Z") inspect!(@time.ZoneOffset::of!(hours=8), content="+08:00") @@ -38,6 +39,7 @@ test "of" { assert_true!(@time.ZoneOffset::of?(hours=-18, seconds=1).is_err()) } +///| test "from_seconds" { inspect!(@time.ZoneOffset::from_seconds!(8 * 60 * 60), content="+08:00") inspect!(@time.ZoneOffset::from_seconds!(0), content="Z") @@ -47,6 +49,7 @@ test "from_seconds" { assert_true!(@time.ZoneOffset::from_seconds?(-19 * 60 * 60).is_err()) } +///| test "utc" { inspect!(@time.utc_offset, content="Z") inspect!(@time.utc_offset.id(), content="Z") @@ -54,6 +57,7 @@ test "utc" { inspect!(@time.utc_offset.is_dst(), content="false") } +///| test "compare" { let o1 = @time.ZoneOffset::from_seconds!(10) let o2 = @time.ZoneOffset::from_seconds!(-10) diff --git a/time/zone_test.mbt b/time/zone_test.mbt index 2ca0686..34e764d 100644 --- a/time/zone_test.mbt +++ b/time/zone_test.mbt @@ -12,11 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. +///| test "fixed" { inspect!(@time.fixed_zone!("CST", 8 * 60 * 60), content="CST") inspect!(@time.fixed_zone!("CST", 8 * 60 * 60).is_fixed(), content="true") } +///| test "utc" { inspect!(@time.utc_zone, content="UTC") } diff --git a/time/zone_wbtest.mbt b/time/zone_wbtest.mbt index c787e49..2dadf7b 100644 --- a/time/zone_wbtest.mbt +++ b/time/zone_wbtest.mbt @@ -12,10 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. +///| test "fixed" { inspect!(fixed_zone!("CST", 8 * 60 * 60).offsets, content="[+08:00]") } +///| test "utc" { inspect!(utc_zone.offsets, content="[Z]") } diff --git a/time/zoned_date_time_test.mbt b/time/zoned_date_time_test.mbt index 9744c9c..ed349dd 100644 --- a/time/zoned_date_time_test.mbt +++ b/time/zoned_date_time_test.mbt @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +///| test "date_time" { let zone = @time.fixed_zone!("Asia/Shanghai", 8 * 60 * 60) inspect!( @@ -20,6 +21,7 @@ test "date_time" { ) } +///| test "unix" { let zone = @time.fixed_zone!("Asia/Shanghai", 8 * 60 * 60) inspect!( @@ -28,6 +30,7 @@ test "unix" { ) } +///| test "of" { inspect!( @time.ZonedDateTime::of!(2000, 1, 1, hour=1, minute=2, second=3), @@ -40,6 +43,7 @@ test "of" { ) } +///| test "from_plain_datetime" { let zone = @time.fixed_zone!("Asia/Shanghai", 8 * 60 * 60) let datetime = @time.PlainDateTime::of!(2000, 1, 1) @@ -49,6 +53,7 @@ test "from_plain_datetime" { ) } +///| test "from_unix_second" { let zone = @time.fixed_zone!("Asia/Shanghai", 8 * 60 * 60) inspect!( @@ -65,6 +70,7 @@ test "from_unix_second" { ) } +///| test "to_unix_second" { let zone = @time.fixed_zone!("Asia/Shanghai", 8 * 60 * 60) inspect!(@time.ZonedDateTime::of!(1970, 1, 1).to_unix_second(), content="0") @@ -74,6 +80,7 @@ test "to_unix_second" { ) } +///| test "conversions" { let zone = @time.fixed_zone!("Asia/Shanghai", 8 * 60 * 60) let zdt = @time.ZonedDateTime::of!( @@ -91,6 +98,7 @@ test "conversions" { inspect!(zdt.to_plain_date_time(), content="2000-01-01T01:02:03") } +///| test "getters" { let zone = @time.fixed_zone!("Asia/Shanghai", 8 * 60 * 60) let zdt = @time.ZonedDateTime::of!( @@ -121,6 +129,7 @@ test "getters" { inspect!(zdt.offset(), content="+08:00") } +///| test "add_years" { let zone = @time.fixed_zone!("Asia/Shanghai", 8 * 60 * 60) let zdt = @time.ZonedDateTime::of!( @@ -138,6 +147,7 @@ test "add_years" { ) } +///| test "add_months" { let zone = @time.fixed_zone!("Asia/Shanghai", 8 * 60 * 60) let zdt = @time.ZonedDateTime::of!( @@ -155,6 +165,7 @@ test "add_months" { ) } +///| test "add_weeks" { let zone = @time.fixed_zone!("Asia/Shanghai", 8 * 60 * 60) let zdt = @time.ZonedDateTime::of!( @@ -172,6 +183,7 @@ test "add_weeks" { ) } +///| test "add_days" { let zone = @time.fixed_zone!("Asia/Shanghai", 8 * 60 * 60) let zdt = @time.ZonedDateTime::of!( @@ -189,6 +201,7 @@ test "add_days" { ) } +///| test "add_hours" { let zone = @time.fixed_zone!("Asia/Shanghai", 8 * 60 * 60) let zdt = @time.ZonedDateTime::of!( @@ -206,6 +219,7 @@ test "add_hours" { ) } +///| test "add_minutes" { let zone = @time.fixed_zone!("Asia/Shanghai", 8 * 60 * 60) let zdt = @time.ZonedDateTime::of!( @@ -223,6 +237,7 @@ test "add_minutes" { ) } +///| test "add_seconds" { let zone = @time.fixed_zone!("Asia/Shanghai", 8 * 60 * 60) let zdt = @time.ZonedDateTime::of!( @@ -240,6 +255,7 @@ test "add_seconds" { ) } +///| test "add_nanoseconds" { let zone = @time.fixed_zone!("Asia/Shanghai", 8 * 60 * 60) let zdt = @time.ZonedDateTime::of!( @@ -257,6 +273,7 @@ test "add_nanoseconds" { ) } +///| test "with_year" { let zone = @time.fixed_zone!("Asia/Shanghai", 8 * 60 * 60) let zdt = @time.ZonedDateTime::of!( @@ -274,6 +291,7 @@ test "with_year" { ) } +///| test "with_month" { let zone = @time.fixed_zone!("Asia/Shanghai", 8 * 60 * 60) let zdt = @time.ZonedDateTime::of!( @@ -291,6 +309,7 @@ test "with_month" { ) } +///| test "with_day" { let zone = @time.fixed_zone!("Asia/Shanghai", 8 * 60 * 60) let zdt = @time.ZonedDateTime::of!( @@ -308,6 +327,7 @@ test "with_day" { ) } +///| test "with_ordinal" { let zone = @time.fixed_zone!("Asia/Shanghai", 8 * 60 * 60) let zdt = @time.ZonedDateTime::of!( @@ -325,6 +345,7 @@ test "with_ordinal" { ) } +///| test "with_hour" { let zone = @time.fixed_zone!("Asia/Shanghai", 8 * 60 * 60) let zdt = @time.ZonedDateTime::of!( @@ -342,6 +363,7 @@ test "with_hour" { ) } +///| test "with_minute" { let zone = @time.fixed_zone!("Asia/Shanghai", 8 * 60 * 60) let zdt = @time.ZonedDateTime::of!( @@ -359,6 +381,7 @@ test "with_minute" { ) } +///| test "with_second" { let zone = @time.fixed_zone!("Asia/Shanghai", 8 * 60 * 60) let zdt = @time.ZonedDateTime::of!( @@ -376,6 +399,7 @@ test "with_second" { ) } +///| test "with_nanosecond" { let zone = @time.fixed_zone!("Asia/Shanghai", 8 * 60 * 60) let zdt = @time.ZonedDateTime::of!( diff --git a/uuid/uuid.mbt b/uuid/uuid.mbt index 911ed12..f3e6d0f 100644 --- a/uuid/uuid.mbt +++ b/uuid/uuid.mbt @@ -77,6 +77,7 @@ pub fn to_bytes(self : UUID) -> Bytes { Bytes::from_fixedarray(rv) } +///| test "bytes" { let buf = Bytes::from_array( [201, 130, 251, 104, 223, 80, 76, 161, 145, 248, 186, 162, 4, 9, 229, 185].map( diff --git a/uuid/uuid_test.mbt b/uuid/uuid_test.mbt index 5ece3ad..a1d487c 100644 --- a/uuid/uuid_test.mbt +++ b/uuid/uuid_test.mbt @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +///| test "from_hex" { let hex = "13cb501c-1234-5678-9034-abcdef937e20" inspect!(@uuid.from_hex!(hex), content=hex) @@ -23,6 +24,7 @@ test "from_hex" { assert_true!(@uuid.from_hex?("13cb501c-99a8-c889-3234").is_err()) } +///| test "ops" { let hex = "72212911-64d1-c441-e87d-de89b955ea34" let u1 = @uuid.from_hex!(hex) diff --git a/uuid/variant.mbt b/uuid/variant.mbt index e7632ba..7d5b3cc 100644 --- a/uuid/variant.mbt +++ b/uuid/variant.mbt @@ -101,6 +101,7 @@ pub fn as_version(self : UUID, version : Version) -> UUID { { hi, lo } } +///| test "variant" { inspect!( from_hex!("81a277a6-771b-1a55-6246-fa3763226aa0").variant(), @@ -120,6 +121,7 @@ test "variant" { ) } +///| test "version" { let u = from_hex!("907976bf-6784-5a4f-5d7d-33c04dd8fa1a") inspect!(u.version(), content="None")