Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit752a2a8

Browse files
committed
add tests for countSubstring
1 parentd5dfbfc commit752a2a8

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

‎src/util.test.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import{it,expect}from"vitest"
2-
import{parseRemoteAuthority,toSafeHost}from"./util"
1+
import{describe,it,expect}from"vitest"
2+
import{countSubstring,parseRemoteAuthority,toSafeHost}from"./util"
33

44
it("ignore unrelated authorities",async()=>{
55
consttests=[
@@ -73,3 +73,35 @@ it("escapes url host", async () => {
7373
expect(()=>toSafeHost("invalid url")).toThrow("Invalid URL")
7474
expect(toSafeHost("http://ignore-port.com:8080")).toBe("ignore-port.com")
7575
})
76+
77+
describe("countSubstring",()=>{
78+
it("handles empty strings",()=>{
79+
expect(countSubstring("","")).toBe(0)
80+
expect(countSubstring("foo","")).toBe(0)
81+
expect(countSubstring("","foo")).toBe(0)
82+
})
83+
84+
it("handles single character",()=>{
85+
expect(countSubstring("a","a")).toBe(1)
86+
expect(countSubstring("a","b")).toBe(0)
87+
expect(countSubstring("a","aa")).toBe(2)
88+
expect(countSubstring("a","aaa")).toBe(3)
89+
expect(countSubstring("a","baaa")).toBe(3)
90+
})
91+
92+
it("handles multiple characters",()=>{
93+
expect(countSubstring("foo","foo")).toBe(1)
94+
expect(countSubstring("foo","bar")).toBe(0)
95+
expect(countSubstring("foo","foobar")).toBe(1)
96+
expect(countSubstring("foo","foobarbaz")).toBe(1)
97+
expect(countSubstring("foo","foobarbazfoo")).toBe(2)
98+
expect(countSubstring("foo","foobarbazfoof")).toBe(2)
99+
})
100+
101+
it("does not handle overlapping substrings",()=>{
102+
expect(countSubstring("aa","aaa")).toBe(1)
103+
expect(countSubstring("aa","aaaa")).toBe(2)
104+
expect(countSubstring("aa","aaaaa")).toBe(2)
105+
expect(countSubstring("aa","aaaaaa")).toBe(3)
106+
})
107+
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp