Skip to content

Commit db8294b

Browse files
authored
Merge branch 'main' into revert-bytesview-primitive
2 parents db40d80 + d86f3bb commit db8294b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+562
-500
lines changed

array/array.mbt

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,5 +302,27 @@ pub impl[X : @quickcheck.Arbitrary] @quickcheck.Arbitrary for Array[X] with arbi
302302
303303
///|
304304
pub fn join(self : Array[String], separator : String) -> String {
305-
@string.concat(self, separator~)
305+
match self {
306+
[] => ""
307+
[hd, .. tl] => {
308+
let mut size_hint = hd.length()
309+
for s in tl {
310+
size_hint += s.length() + separator.length()
311+
}
312+
size_hint = size_hint << 1
313+
let buf = StringBuilder::new(size_hint~)
314+
buf.write_string(hd)
315+
if separator == "" {
316+
for s in tl {
317+
buf.write_string(s)
318+
}
319+
} else {
320+
for s in tl {
321+
buf.write_string(separator)
322+
buf.write_string(s)
323+
}
324+
}
325+
buf.to_string()
326+
}
327+
}
306328
}

array/array_test.mbt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -716,8 +716,7 @@ test "Array[String]::join" {
716716
inspect(["a", "b", "c"].join(","), content="a,b,c")
717717
inspect(["a", "b", "c"].join(""), content="abc")
718718
inspect(["a", "b", "c"].join(" "), content="a b c")
719-
inspect(["a", "b", "c"].join(" "), content="a b c")
720-
inspect(["a", "b", "c"].join(" "), content="a b c")
721-
inspect(["a", "b", "c"].join(" "), content="a b c")
722-
inspect(["a", "b", "c"].join(" "), content="a b c")
719+
inspect!(["123", "456"].join(""), content="123456")
720+
inspect!(["aaa", "bbb", "ccc"].join(" "), content="aaa bbb ccc")
721+
inspect!([].join(" "))
723722
}

bool/README.mbt.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ The package allows converting boolean values to various integer types. `true` is
88

99
```moonbit
1010
test "bool to integer conversions" {
11-
// Direct function calls
12-
inspect(@bool.to_int(true), content="1")
13-
inspect(@bool.to_int(false), content="0")
14-
1511
// Method syntax
1612
inspect(true.to_int(), content="1")
1713
inspect(false.to_int(), content="0")

builtin/builtin.mbti

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ impl String {
540540
get(String, Int) -> Char
541541
length(String) -> Int
542542
make(Int, Char) -> String
543+
#deprecated
543544
op_get(String, Int) -> Char
544545
substring(String, start~ : Int = .., end? : Int) -> String
545546
to_string(String) -> String
@@ -557,6 +558,7 @@ impl FixedArray {
557558
blit_from_string(Self[Byte], Int, String, Int, Int) -> Unit
558559
blit_to[A](Self[A], Self[A], len~ : Int, src_offset~ : Int = .., dst_offset~ : Int = ..) -> Unit
559560
fill[T](Self[T], T) -> Unit
561+
#deprecated
560562
get[T](Self[T], Int) -> T
561563
is_empty[T](Self[T]) -> Bool
562564
iter[T](Self[T]) -> Iter[T]
@@ -580,6 +582,7 @@ impl Bytes {
580582
make(Int, Byte) -> Bytes
581583
makei(Int, (Int) -> Byte) -> Bytes
582584
new(Int) -> Bytes
585+
#deprecated
583586
of_string(String) -> Bytes
584587
op_get(Bytes, Int) -> Byte
585588
to_unchecked_string(Bytes, offset~ : Int = .., length~ : Int = ..) -> String

builtin/byte.mbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ pub impl Compare for Byte with compare(self : Byte, that : Byte) -> Int {
132132
}
133133
134134
///|
135-
fn alphabet(self : Int) -> String {
136-
match self {
135+
fn alphabet(x : Int) -> String {
136+
match x {
137137
0 => "0"
138138
1 => "1"
139139
2 => "2"

builtin/bytes.mbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ pub fn Bytes::makei(length : Int, value : (Int) -> Byte) -> Bytes {
6868
/// inspect(bytes, content="b\"\\x41\\x00\\x42\\x00\\x43\\x00\"")
6969
/// }
7070
/// ```
71+
#deprecated("Use `str.to_bytes()` instead")
7172
pub fn Bytes::of_string(str : String) -> Bytes {
7273
FixedArray::make(str.length() * 2, Byte::default())
7374
..blit_from_string(0, str, 0, str.length())

builtin/bytes_test.mbt

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,16 @@
1313
// limitations under the License.
1414

1515
///|
16-
test "to_string" {
17-
let bytes = Bytes::of_string("Hello, World!")
18-
assert_eq!(bytes.to_unchecked_string(), "Hello, World!")
19-
}
16+
const HELLO_WORLD = b"H\x00e\x00l\x00l\x00o\x00,\x00 \x00W\x00o\x00r\x00l\x00d\x00!\x00"
2017

2118
///|
22-
test "of_string" {
23-
let str = "Hello, World!"
24-
let bytes = Bytes::of_string(str)
25-
assert_eq!(bytes.length(), str.length() * 2)
19+
test "to_string" {
20+
assert_eq!(HELLO_WORLD.to_unchecked_string(), "Hello, World!")
2621
}
2722

2823
///|
2924
test "sub_string" {
30-
let bytes = Bytes::of_string("Hello, World!")
31-
assert_eq!(bytes.to_unchecked_string(offset=0, length=5 * 2), "Hello")
32-
// assert_eq(bytes.sub_string(10, 5 * 2), "World")?
25+
assert_eq!(HELLO_WORLD.to_unchecked_string(offset=0, length=5 * 2), "Hello")
3326
}
3427

3528
///|
@@ -42,9 +35,11 @@ test "blit_from_string" {
4235

4336
///|
4437
test "copy" {
45-
let bytes = Bytes::of_string("Hello, World!")
46-
let copy_bytes = bytes.copy()
47-
assert_eq!(copy_bytes.to_unchecked_string(), bytes.to_unchecked_string())
38+
let copy_bytes = HELLO_WORLD.copy()
39+
assert_eq!(
40+
copy_bytes.to_unchecked_string(),
41+
HELLO_WORLD.to_unchecked_string(),
42+
)
4843
}
4944

5045
///|
@@ -157,10 +152,9 @@ test "set_utf16be_char" {
157152

158153
///|
159154
test "op_equal" {
160-
let bytes = Bytes::of_string("Hello, World!")
161-
let copy_bytes = bytes.copy()
162-
assert_eq!(bytes, copy_bytes)
163-
assert_not_eq!(bytes, Bytes::new(10))
155+
let copy_bytes = HELLO_WORLD.copy()
156+
assert_eq!(HELLO_WORLD, copy_bytes)
157+
assert_not_eq!(HELLO_WORLD, Bytes::new(10))
164158
}
165159

166160
///|

builtin/intrinsics.mbt

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,6 +1581,7 @@ pub fn[T] FixedArray::unsafe_set(
15811581
/// inspect(arr.get(3), content="None")
15821582
/// }
15831583
/// ```
1584+
#deprecated("use `arr.op_get(i)`(arr[i]) instead")
15841585
pub fn[T] FixedArray::get(self : FixedArray[T], idx : Int) -> T = "%fixedarray.get"
15851586

15861587
///|
@@ -1731,31 +1732,7 @@ pub fn String::length(self : String) -> Int = "%string_length"
17311732
pub fn String::charcode_length(self : String) -> Int = "%string_length"
17321733

17331734
///|
1734-
/// Retrieves the charcode (UTF-16 code unit) at the specified index in a string.
1735-
///
1736-
/// Parameters:
1737-
///
1738-
/// * `string` : The string from which to retrieve the charcode.
1739-
/// * `index` : The position in the string from which to retrieve the charcode.
1740-
///
1741-
/// Throws a runtime error if `index` is negative or greater than or equal to the
1742-
/// length of the string.
1743-
///
1744-
/// Example:
1745-
///
1746-
/// ```moonbit
1747-
/// test "String::op_get" {
1748-
/// let s = "Hello, 世界!"
1749-
/// inspect(s[0], content="H")
1750-
/// inspect(s[7], content="世")
1751-
/// }
1752-
///
1753-
/// test "panic String::op_get/out_of_bounds" {
1754-
/// let s = "Hello"
1755-
/// ignore(s[5]) // Index out of bounds
1756-
/// }
1757-
/// ```
1758-
///
1735+
#deprecated("use `String::charcode_at` and `Int::to_char` instead")
17591736
pub fn String::op_get(self : String, idx : Int) -> Char = "%string_get"
17601737

17611738
///|

builtin/panic_test.mbt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,19 +241,19 @@ test "panic from_octets coverage for empty octets" {
241241

242242
///|
243243
test "panic sub_string with invalid byte_length" {
244-
let bytes = Bytes::of_string("Hello, World!")
244+
let bytes = b"Hello, World!"
245245
bytes.to_unchecked_string(offset=0, length=-1) |> ignore
246246
}
247247

248248
///|
249249
test "panic sub_string with invalid byte_offset" {
250-
let bytes = Bytes::of_string("Hello, World!")
250+
let bytes = b"Hello, World!"
251251
bytes.to_unchecked_string(offset=-1, length=5) |> ignore
252252
}
253253

254254
///|
255255
test "panic sub_string with invalid byte_offset + byte_length" {
256-
let bytes = Bytes::of_string("Hello, World!")
256+
let bytes = b"Hello, World!"
257257
bytes.to_unchecked_string(offset=0, length=bytes.length() + 1) |> ignore
258258
}
259259

byte/README.mbt.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ test "byte conversion" {
2222
let byte = b'A'
2323
inspect(byte.to_uint64(), content="65")
2424
let byte = b' '
25-
inspect(@byte.to_uint64(byte), content="32")
25+
inspect(byte.to_uint64(), content="32")
2626
}
2727
```
2828

byte/byte_test.mbt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,25 @@ test "int to byte" {
3030

3131
///|
3232
test "grouped test for boundary cases" {
33-
inspect(@moonbitlang/core/byte.to_uint64(b'\x00'), content="0")
34-
inspect(@moonbitlang/core/byte.to_uint64(b'\xFF'), content="255")
33+
inspect(b'\x00'.to_uint64(), content="0")
34+
inspect(b'\xFF'.to_uint64(), content="255")
3535
}
3636

3737
///|
3838
test "grouped test for random cases" {
39-
inspect(@moonbitlang/core/byte.to_uint64(b'\x10'), content="16")
40-
inspect(@moonbitlang/core/byte.to_uint64(b'\x2A'), content="42")
41-
inspect(@moonbitlang/core/byte.to_uint64(b'\x7F'), content="127")
42-
inspect(@moonbitlang/core/byte.to_uint64(b'\x80'), content="128")
43-
inspect(@moonbitlang/core/byte.to_uint64(b'\xAA'), content="170")
44-
inspect(@moonbitlang/core/byte.to_uint64(b'\x55'), content="85")
39+
inspect(b'\x10'.to_uint64(), content="16")
40+
inspect(b'\x2A'.to_uint64(), content="42")
41+
inspect(b'\x7F'.to_uint64(), content="127")
42+
inspect(b'\x80'.to_uint64(), content="128")
43+
inspect(b'\xAA'.to_uint64(), content="170")
44+
inspect(b'\x55'.to_uint64(), content="85")
4545
}
4646

4747
///|
4848
test "additional random cases" {
49-
inspect(@moonbitlang/core/byte.to_uint64(b'\x3C'), content="60")
50-
inspect(@moonbitlang/core/byte.to_uint64(b'\x64'), content="100")
51-
inspect(@moonbitlang/core/byte.to_uint64(b'\x99'), content="153")
49+
inspect(b'\x3C'.to_uint64(), content="60")
50+
inspect(b'\x64'.to_uint64(), content="100")
51+
inspect(b'\x99'.to_uint64(), content="153")
5252
}
5353

5454
///|

char/README.mbt.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ Functions for determining if a character belongs to various ASCII categories.
99
```moonbit
1010
test "ascii classification" {
1111
// Basic ASCII checks
12-
inspect(@char.is_ascii('A'), content="true")
13-
inspect(@char.is_ascii('λ'), content="false")
12+
inspect('A'.is_ascii(), content="true")
13+
inspect('λ'.is_ascii(), content="false")
1414
1515
// Letter classification
16-
inspect(@char.is_ascii_alphabetic('Z'), content="true")
17-
inspect(@char.is_ascii_alphabetic('1'), content="false")
16+
inspect('Z'.is_ascii_alphabetic(), content="true")
17+
inspect('1'.is_ascii_alphabetic(), content="false")
1818
1919
// Case classification
20-
inspect(@char.is_ascii_uppercase('A'), content="true")
21-
inspect(@char.is_ascii_uppercase('a'), content="false")
22-
inspect(@char.is_ascii_lowercase('a'), content="true")
23-
inspect(@char.is_ascii_lowercase('A'), content="false")
20+
inspect('A'.is_ascii_uppercase(), content="true")
21+
inspect('a'.is_ascii_uppercase(), content="false")
22+
inspect('a'.is_ascii_lowercase(), content="true")
23+
inspect('A'.is_ascii_lowercase(), content="false")
2424
}
2525
```
2626

@@ -31,24 +31,24 @@ Functions for identifying digits in different number bases.
3131
```moonbit
3232
test "number classification" {
3333
// Decimal digits
34-
inspect(@char.is_ascii_digit('5'), content="true")
35-
inspect(@char.is_ascii_digit('x'), content="false")
34+
inspect('5'.is_ascii_digit(), content="true")
35+
inspect('x'.is_ascii_digit(), content="false")
3636
3737
// Hexadecimal digits
38-
inspect(@char.is_ascii_hexdigit('F'), content="true")
39-
inspect(@char.is_ascii_hexdigit('G'), content="false")
38+
inspect('F'.is_ascii_hexdigit(), content="true")
39+
inspect('G'.is_ascii_hexdigit(), content="false")
4040
4141
// Octal digits
42-
inspect(@char.is_ascii_octdigit('7'), content="true")
43-
inspect(@char.is_ascii_octdigit('8'), content="false")
42+
inspect('7'.is_ascii_octdigit(), content="true")
43+
inspect('8'.is_ascii_octdigit(), content="false")
4444
4545
// Custom base digits
46-
inspect(@char.is_digit('5', 6U), content="true")
47-
inspect(@char.is_digit('6', 6U), content="false")
46+
inspect('5'.is_digit(6U), content="true")
47+
inspect('6'.is_digit(6U), content="false")
4848
4949
// General numeric characters
50-
inspect(@char.is_numeric('1'), content="true")
51-
inspect(@char.is_numeric('A'), content="false")
50+
inspect('1'.is_numeric(), content="true")
51+
inspect('A'.is_numeric(), content="false")
5252
}
5353
```
5454

@@ -59,17 +59,17 @@ Functions for identifying whitespace, control characters and other special chara
5959
```moonbit
6060
test "special characters" {
6161
// Whitespace characters
62-
inspect(@char.is_ascii_whitespace(' '), content="true")
63-
inspect(@char.is_whitespace('\n'), content="true")
62+
inspect(' '.is_ascii_whitespace(), content="true")
63+
inspect('\n'.is_whitespace(), content="true")
6464
6565
// Control characters
66-
inspect(@char.is_ascii_control('\u0000'), content="true")
67-
inspect(@char.is_control('\u007F'), content="true")
66+
inspect('\u0000'.is_ascii_control(), content="true")
67+
inspect('\u007F'.is_control(), content="true")
6868
6969
// Graphic and punctuation characters
70-
inspect(@char.is_ascii_graphic('!'), content="true")
71-
inspect(@char.is_ascii_graphic(' '), content="false")
72-
inspect(@char.is_ascii_punctuation(','), content="true")
70+
inspect('!'.is_ascii_graphic(), content="true")
71+
inspect(' '.is_ascii_graphic(), content="false")
72+
inspect(','.is_ascii_punctuation(), content="true")
7373
}
7474
```
7575

deque/deque.mbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ pub fn[A] unsafe_pop_front(self : T[A]) -> Unit {
352352
#deprecated("Use `unsafe_pop_front` instead")
353353
#coverage.skip
354354
pub fn[A] pop_front_exn(self : T[A]) -> Unit {
355-
unsafe_pop_front(self)
355+
self.unsafe_pop_front()
356356
}
357357
358358
///|
@@ -409,7 +409,7 @@ pub fn[A] unsafe_pop_back(self : T[A]) -> Unit {
409409
#deprecated("Use `unsafe_pop_back` instead")
410410
#coverage.skip
411411
pub fn[A] pop_back_exn(self : T[A]) -> Unit {
412-
unsafe_pop_back(self)
412+
self.unsafe_pop_back()
413413
}
414414
415415
///|

deque/deque_test.mbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ test "test_clone_from" {
693693
for _idx in 0..<pfu {
694694
u.push_front(2)
695695
}
696-
let v = @deque.copy(u)
696+
let v = u.copy()
697697
assert_eq!(v, u)
698698
}
699699
}

0 commit comments

Comments
 (0)