Skip to content

Commit

Permalink
refactor(core): use snapshots for interpreter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PJColombo committed Jan 10, 2023
1 parent 5894bd0 commit 64229bb
Show file tree
Hide file tree
Showing 30 changed files with 7,050 additions and 4,206 deletions.
23 changes: 20 additions & 3 deletions common/test/src/test-helpers/cas11.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,23 @@ import { inspect } from 'util';
const { CommandExpression } = NodeType;
const { Between, Equal, Greater } = ComparisonType;

export type ForEachCase<V = any, E = any> = {
message?: string;
value: V;
expected?: E;
title: string;
};
export type Case = [string, any, string?];

export type InterpreterCase = [Node, any, string?];
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const deepConsoleLog = (thing: any): void =>
console.log(inspect(thing, false, null, true));

export const runParser = (
export function runParser(
parser: Parser<any, string, any>,
value: string,
): any => {
): any {
const res = withData<any, string, NodeParserState>(parser)(
createParserState(),
).run(value);
Expand All @@ -53,7 +59,18 @@ export const runParser = (
}

return res.result;
};
}

export function runParserError(parser: NodeParser, text: string): string {
const parserState = createParserState();
const res = withData<any, string, NodeParserState>(parser)(parserState).run(
text,
);

expect(res.isError, 'error not thrown').to.be.true;

return (res as Err<string, NodeParserState>).error;
}

export const runCases = (
caseOrCases: Case | Case[],
Expand Down
2 changes: 1 addition & 1 deletion core/evmcrispr/src/parsers/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
openingCharParser,
} from './utils';

export const ARRAY_PARSER_ERROR = 'ArrayParserError';
const ARRAY_PARSER_ERROR = 'ArrayParserError';

export const arrayExpressionParser: NodeParser<ArrayExpressionNode> =
recursiveParser(() =>
Expand Down
2 changes: 1 addition & 1 deletion core/evmcrispr/src/parsers/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ const commandArgsParser = coroutine(function* () {
return commandArgOrOpt;
});

export const COMMAND_PARSER_ERROR = 'CommandParserError';
const COMMAND_PARSER_ERROR = 'CommandParserError';

export const endOfCommandParser = choice([endLine, lookAhead(endOfInput)]);

Expand Down
2 changes: 1 addition & 1 deletion core/evmcrispr/src/parsers/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
openingCharParser,
} from './utils';

export const HELPER_PARSER_ERROR = 'HelperParserError';
const HELPER_PARSER_ERROR = 'HelperParserError';

const helperNameParser = recursiveParser(() =>
takeLeft(regex(/^(?!-|\.)[a-zA-Z\-.]+(?<!-|\.)/))(
Expand Down
4 changes: 2 additions & 2 deletions core/evmcrispr/src/parsers/primaries/identifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import { NodeType } from '../../types';
import { buildParserError } from '../../utils/parsers';
import { createNodeLocation, enclosingLookaheadParser, locate } from '../utils';

export const VARIABLE_PARSER_ERROR = 'VariableParserError';
const VARIABLE_PARSER_ERROR = 'VariableParserError';

export const PROBABLE_IDENTIFIER_PARSER_ERROR = 'IdentifierParserError';
const PROBABLE_IDENTIFIER_PARSER_ERROR = 'IdentifierParserError';

export const variableIdentifierParser: EnclosingNodeParser<
VariableIdentifierNode
Expand Down
2 changes: 1 addition & 1 deletion core/evmcrispr/src/parsers/primaries/literals/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
locate,
} from '../../utils';

export const ADDRESS_PARSER_ERROR = 'AddressParserError';
const ADDRESS_PARSER_ERROR = 'AddressParserError';

export const addressParser: EnclosingNodeParser<AddressLiteralNode> = (
enclosingParsers = [],
Expand Down
2 changes: 1 addition & 1 deletion core/evmcrispr/src/parsers/primaries/literals/boolean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
locate,
} from '../../utils';

export const BOOLEAN_PARSER_ERROR = 'BooleanParserError';
const BOOLEAN_PARSER_ERROR = 'BooleanParserError';

export const booleanParser: EnclosingNodeParser<BooleanLiteralNode> = (
enclosingParsers = [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
locate,
} from '../../utils';

export const HEXADECIMAL_PARSER_ERROR = 'HexadecimalParserError';
const HEXADECIMAL_PARSER_ERROR = 'HexadecimalParserError';

export const hexadecimalParser: EnclosingNodeParser<BytesLiteralNode> = (
enclosingParsers = [],
Expand Down
2 changes: 1 addition & 1 deletion core/evmcrispr/src/parsers/primaries/literals/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
locate,
} from '../../utils';

export const STRING_PARSER_ERROR = 'StringParserError';
const STRING_PARSER_ERROR = 'StringParserError';

export const stringParser: EnclosingNodeParser<StringLiteralNode> = (
enclosingParsers = [],
Expand Down
Loading

0 comments on commit 64229bb

Please sign in to comment.