Skip to content
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
10 changes: 10 additions & 0 deletions array/array_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,13 @@ test "panic fill with invalid end" {
let arr = [1, 2, 3, 4, 5]
arr.fill(0, start=2, end=10)
}

///|
test "Array::join with Char" {
let chars : Array[Char] = ['h', 'e', 'l', 'l', 'o']
let result = chars.join("")
inspect(result, content="hello")
let chars2 : Array[Char] = ['a', 'b', 'c']
let result2 = chars2.join(", ")
inspect(result2, content="a, b, c")
}
1 change: 1 addition & 0 deletions string/pkg.generated.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ impl ToJson for StringView
pub trait ToStringView {
to_string_view(Self) -> StringView
}
impl ToStringView for Char
impl ToStringView for String
impl ToStringView for StringView

6 changes: 6 additions & 0 deletions string/string_like.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ pub impl ToStringView for String with to_string_view(self) -> StringView {
pub impl ToStringView for StringView with to_string_view(self) -> StringView {
self
}

///|
/// Implements ToStringView for Char, enabling operations like Array::join on Array[Char]
pub impl ToStringView for Char with to_string_view(self) -> StringView {
[self]
}
41 changes: 41 additions & 0 deletions string/tostringview_char_demo_test.mbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2025 International Digital Economy Academy
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

///|
test "ToStringView for Char - comprehensive demo" {
// Test 1: Simple join without separator
let chars1 : Array[Char] = ['h', 'e', 'l', 'l', 'o']
let result1 = chars1.join("")
inspect(result1, content="hello")

// Test 2: Join with separator
let chars2 : Array[Char] = ['a', 'b', 'c', 'd']
let result2 = chars2.join(", ")
inspect(result2, content="a, b, c, d")

// Test 3: Empty array
let chars3 : Array[Char] = []
let result3 = chars3.join("-")
inspect(result3, content="")

// Test 4: Single character
let chars4 : Array[Char] = ['x']
let result4 = chars4.join(" | ")
inspect(result4, content="x")

// Test 5: Unicode characters
let chars5 : Array[Char] = ['🌟', '✨', '🎉']
let result5 = chars5.join(" ")
inspect(result5, content="🌟 ✨ 🎉")
}