Skip to content

Commit

Permalink
Refactoring tests (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
arduano authored Apr 27, 2024
1 parent 1252ab3 commit af43fae
Show file tree
Hide file tree
Showing 12 changed files with 935 additions and 433 deletions.
10 changes: 2 additions & 8 deletions nixjs-rt/src/errors/errorMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ function isErrorMessagePart(part: any): part is ErrorMessagePart {
);
}

function isErrorMessage(parts: any): parts is ErrorMessage {
if (!Array.isArray(parts)) {
return false;
}

return parts.every(isErrorMessagePart);
}

/** A helper to convert instances to their respective class in a type-safe way, for better error messages */
export function instanceToClass(instance: NixTypeInstance | NixTypeClass) {
if (instance instanceof NixBool) {
Expand Down Expand Up @@ -144,6 +136,8 @@ export function errTypes(...types: NixTypeClass[]): ErrorMessage {
}
message.push(...errType(types[i]));
}

return message;
}

export function highlighted(message: string | ErrorMessage): ErrorMessage {
Expand Down
File renamed without changes.
9 changes: 8 additions & 1 deletion nixjs-rt/src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export abstract class NixType {
}

asString(): string {
throw typeMismatchError(this, NixString);
throw typeMismatchError(this, [NixString, Path]);
}

concat(other: NixType): NixList {
Expand Down Expand Up @@ -956,6 +956,9 @@ export class NixString extends NixType {
if (rhs instanceof NixString) {
return new NixString(this.value + rhs.value);
}
if (rhs instanceof Path) {
return new NixString(normalizePath(this.value + rhs.path));
}
return super.add(rhs);
}

Expand Down Expand Up @@ -1023,6 +1026,10 @@ export class Path extends NixType {
return _nixBoolFromJs(this.path < rhs.path);
}

asString(): string {
return this.path;
}

toJs() {
return this.path;
}
Expand Down
1 change: 0 additions & 1 deletion src/eval/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ pub mod emit_js;
pub mod error;
pub mod execution;
pub mod helpers;
pub mod tests;
pub mod types;
Loading

0 comments on commit af43fae

Please sign in to comment.