Skip to content

fix: SSHConfig: check for multiple start/end blocks #510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 23, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add tests for countSubstring
  • Loading branch information
johnstcn committed May 21, 2025
commit 752a2a86d85bb2d149f675e16b73f28297e1fd62
36 changes: 34 additions & 2 deletions src/util.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { it, expect } from "vitest"
import { parseRemoteAuthority, toSafeHost } from "./util"
import { describe, it, expect } from "vitest"
import { countSubstring, parseRemoteAuthority, toSafeHost } from "./util"

it("ignore unrelated authorities", async () => {
const tests = [
Expand Down Expand Up @@ -73,3 +73,35 @@ it("escapes url host", async () => {
expect(() => toSafeHost("invalid url")).toThrow("Invalid URL")
expect(toSafeHost("http://ignore-port.com:8080")).toBe("ignore-port.com")
})

describe("countSubstring", () => {
it("handles empty strings", () => {
expect(countSubstring("", "")).toBe(0)
expect(countSubstring("foo", "")).toBe(0)
expect(countSubstring("", "foo")).toBe(0)
})

it("handles single character", () => {
expect(countSubstring("a", "a")).toBe(1)
expect(countSubstring("a", "b")).toBe(0)
expect(countSubstring("a", "aa")).toBe(2)
expect(countSubstring("a", "aaa")).toBe(3)
expect(countSubstring("a", "baaa")).toBe(3)
})

it("handles multiple characters", () => {
expect(countSubstring("foo", "foo")).toBe(1)
expect(countSubstring("foo", "bar")).toBe(0)
expect(countSubstring("foo", "foobar")).toBe(1)
expect(countSubstring("foo", "foobarbaz")).toBe(1)
expect(countSubstring("foo", "foobarbazfoo")).toBe(2)
expect(countSubstring("foo", "foobarbazfoof")).toBe(2)
})

it("does not handle overlapping substrings", () => {
expect(countSubstring("aa", "aaa")).toBe(1)
expect(countSubstring("aa", "aaaa")).toBe(2)
expect(countSubstring("aa", "aaaaa")).toBe(2)
expect(countSubstring("aa", "aaaaaa")).toBe(3)
})
})