Skip to content

Commit

Permalink
0.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhargav committed Jul 22, 2023
1 parent 3bd85f8 commit acf2a5f
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.2.4

- Deleted `go.dkinom.dev/baseconv/characters`
- Added tests in `go.dkinom.dev/baseconv/internal/characters`

## 0.2.3

- Retracted `go.dkinom.dev/baseconv/characters`
Expand Down
1 change: 0 additions & 1 deletion characters/doc.go

This file was deleted.

5 changes: 0 additions & 5 deletions characters/go.mod

This file was deleted.

54 changes: 54 additions & 0 deletions internal/characters/ascii_test.go
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()
}
})
}
62 changes: 62 additions & 0 deletions internal/characters/characters_test.go
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")
}
})
}

0 comments on commit acf2a5f

Please sign in to comment.