|
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" |
3 | 3 |
|
4 | 4 | it("ignore unrelated authorities",async()=>{
|
5 | 5 | consttests=[
|
@@ -73,3 +73,35 @@ it("escapes url host", async () => {
|
73 | 73 | expect(()=>toSafeHost("invalid url")).toThrow("Invalid URL")
|
74 | 74 | expect(toSafeHost("http://ignore-port.com:8080")).toBe("ignore-port.com")
|
75 | 75 | })
|
| 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 | +}) |