Skip to content

Add JavaScript tests#51

Merged
jakelazaroff merged 10 commits intomainfrom
jake/add-js-tests
Jan 24, 2025
Merged

Add JavaScript tests#51
jakelazaroff merged 10 commits intomainfrom
jake/add-js-tests

Conversation

@jakelazaroff
Copy link
Contributor

No description provided.

@jakelazaroff jakelazaroff requested a review from paulgb January 24, 2025 16:14
@jakelazaroff jakelazaroff marked this pull request as ready for review January 24, 2025 16:14
const { machine_name } = await fvm.createMachine()
const { instruction_seq } = await fvm.exec('print(123) or 567')
expect(instruction_seq).toBe(0)
const result = await fvm.execResult(machine_name, instruction_seq!!!)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of triple exclamation marks (!!!) is not valid TypeScript syntax. It should be a single exclamation mark for non-null assertion.

Suggested change
const result = await fvm.execResult(machine_name, instruction_seq!!!)
const result = await fvm.execResult(machine_name, instruction_seq!)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use as many exclamation marks as you want!!!!!!!!!!!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, I think ellipsis is wrong here. But could the intent of the code be made more legible using new Boolean(...)? As a reader I'm not sure how it's different than a single !.

Copy link
Contributor Author

@jakelazaroff jakelazaroff Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a non-null assertion — the type is number | undefined and i want it to be number. as number is probably harmless here, i just avoid that in general since you can accidentally cast the type incorrectly if you're not careful. !!! is just more greppable than ! — the likelihood of using it as a unary not is low because it's the same as a single ! (and even if you wanted to coerce to a boolean you'd only use two: !!)

wordier justification if you're interested: https://til.jakelazaroff.com/typescript/assert-that-a-variable-is-not-null-or-undefined/

the real question is, is this property truly optional? is there a case in which the response to exec doesn't include an instruction_seq?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the instruction failed to be submitted (because an existing one is running and it is not interruptable), it won't have an instruction_seq

Jake Lazaroff added 2 commits January 24, 2025 11:57
@jakelazaroff jakelazaroff merged commit cdd5194 into main Jan 24, 2025
4 checks passed
@jakelazaroff jakelazaroff deleted the jake/add-js-tests branch January 24, 2025 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants