Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trycf/20c9e7294bf1e8c15715e6a090522d87 to your computer and use it in GitHub Desktop.
Save trycf/20c9e7294bf1e8c15715e6a090522d87 to your computer and use it in GitHub Desktop.
TryCF Gist
<cfscript>
function testRest(first, ...rest) {
return arguments
}
function run() {
describe("Testing CF's rest operator, eg: function testRest(first, ...rest)", () => {
describe("Expected behaviour", () => {
it("combines all latter argument values into one parameter value when using positional arguments", () => {
actual = testRest("first", "second", "third", "fourth")
expect(actual).toBe([
first = "first",
rest = ["second", "third", "fourth"]
])
writeDump(var=actual, label="actual/expected")
})
it("combines all latter argument values into one parameter value when using named arguments", () => {
actual = testRest(first="first", two="second", three="third", four="fourth")
expect(actual.first).toBe("first")
expect(actual).toHaveKey("rest")
expect(actual.rest).toBe({two="second", three="third", four="fourth"})
})
})
describe("Actual behaviour", () => {
it("doesn't work at all with named arguments", () => {
actual = testRest(first="first", two="second", three="third", four="fourth")
expect(actual.first).toBe("first")
expect(actual?.rest).toBeNull()
expect(actual.keyList().listSort("TEXTNOCASE")).toBe("FIRST,four,REST,three,two")
writeDump(var=actual, label="actual")
writeDump(var={first="first", rest={two="second", three="third", four="fourth"}}, label="expected")
})
it("mishandles specifying a named argument `rest`", () => {
actual = testRest(first="first", rest="rest", two="second", three="third", four="fourth")
expect(actual.first).toBe("first")
expect(actual.rest).toBe("rest")
expected = {
first = "first",
rest = "rest",
two = "second",
three = "third",
four = "fourth"
}
expected.each((k, v) => {
expect(actual[k]).toBe(v)
})
writeDump(var=actual, label="actual")
writeDump(var={first="first", rest={rest="rest", two="second", three="third", four="fourth"}}, label="expected")
})
})
})
}
tinyTest.runTests()
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment