Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save trycf/f78d75b0f5a0200ad1d40aa0671ee3c4 to your computer and use it in GitHub Desktop.
Save trycf/f78d75b0f5a0200ad1d40aa0671ee3c4 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")
})
})
})
}
tinyTest.runTests()
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment