-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bhargav
committed
Jul 22, 2023
1 parent
3bd85f8
commit acf2a5f
Showing
5 changed files
with
121 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package characters | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestIsASCII(t *testing.T) { | ||
t.Run("ASCII string", func(t *testing.T) { | ||
if !isASCII("asdfgh") { | ||
t.Fatal("'asdfgh' contains only ascii characters") | ||
} | ||
}) | ||
|
||
t.Run("Empty string", func(t *testing.T) { | ||
if !isASCII("") { | ||
t.Fatal() | ||
} | ||
}) | ||
|
||
t.Run("Non-ASCII string", func(t *testing.T) { | ||
if isASCII("jklπoi") { | ||
t.Fatal() | ||
} | ||
}) | ||
} | ||
|
||
func TestASCIICharacterIterator(t *testing.T) { | ||
t.Run("ASCII string", func(t *testing.T) { | ||
str := "qwerty" | ||
bytes := []byte(str) | ||
itr := newASCII(str) | ||
|
||
length := 0 | ||
for itr.Next() { | ||
length++ | ||
|
||
if itr.Str() != string(bytes[length-1]) { | ||
t.Fatal() | ||
} | ||
} | ||
|
||
if length != 6 { | ||
t.Fatal("'qwerty' has 6 characters") | ||
} | ||
}) | ||
|
||
t.Run("Empty string", func(t *testing.T) { | ||
itr := newASCII("") | ||
|
||
if itr.Next() { | ||
t.Fatal() | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package characters | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/rivo/uniseg" | ||
) | ||
|
||
func TestCharacterIterator(t *testing.T) { | ||
t.Run("ASCII string", func(t *testing.T) { | ||
str := "zxcvbnm" | ||
bytes := []byte(str) | ||
itr := NewCharacters(str) | ||
|
||
if _, ok := itr.(*ascii); !ok { | ||
t.Fatal("expected ascii iterator") | ||
} | ||
|
||
length := 0 | ||
for itr.Next() { | ||
length++ | ||
|
||
if itr.Str() != string(bytes[length-1]) { | ||
t.Fatal() | ||
} | ||
} | ||
|
||
if length != 7 { | ||
t.Fatal("'zxcvbnm' has 7 characters") | ||
} | ||
}) | ||
|
||
t.Run("Empty string", func(t *testing.T) { | ||
itr := NewCharacters("") | ||
|
||
if _, ok := itr.(*ascii); !ok { | ||
t.Fatal("expected ascii iterator") | ||
} | ||
|
||
if itr.Next() { | ||
t.Fatal() | ||
} | ||
}) | ||
|
||
t.Run("Non-ASCII string", func(t *testing.T) { | ||
str := "0️⃣1️⃣2️⃣3️⃣4️⃣5️⃣6️⃣7️⃣8️⃣9️⃣" | ||
itr := NewCharacters(str) | ||
|
||
if _, ok := itr.(*uniseg.Graphemes); !ok { | ||
t.Fatal("expected graphemes iterator") | ||
} | ||
|
||
length := 0 | ||
for itr.Next() { | ||
length++ | ||
} | ||
|
||
if length != 10 { | ||
t.Fatal("'0️⃣1️⃣2️⃣3️⃣4️⃣5️⃣6️⃣7️⃣8️⃣9️⃣' has 10 characters") | ||
} | ||
}) | ||
} |