Skip to content

Commit

Permalink
Tests for util functions
Browse files Browse the repository at this point in the history
  • Loading branch information
BalaM314 committed Aug 17, 2024
1 parent 75a10fc commit ba94bd1
Show file tree
Hide file tree
Showing 10 changed files with 397 additions and 66 deletions.
46 changes: 23 additions & 23 deletions build/builtin_functions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,28 @@ type PreprocesssedBuiltinFunctionData<TArgs extends BuiltinFunctionArg[], TRetur
};
export declare const getBuiltinFunctions: () => Record<keyof typeof preprocessedBuiltinFunctions, BuiltinFunctionData> & Partial<Record<string, BuiltinFunctionData>>;
export declare const preprocessedBuiltinFunctions: {
LEFT: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
RIGHT: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
MID: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
LENGTH: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
TO_UPPER: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
TO_LOWER: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
UCASE: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
LCASE: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
NUM_TO_STR: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
STR_TO_NUM: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
IS_NUM: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
ASC: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
CHR: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
INT: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
RAND: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
DAY: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
MONTH: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
YEAR: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
DAYINDEX: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
SETDATE: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
TODAY: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
EOF: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
ROUND: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "STRING" | "CHAR" | "BOOLEAN" | "DATE">;
LEFT: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
RIGHT: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
MID: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
LENGTH: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
TO_UPPER: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
TO_LOWER: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
UCASE: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
LCASE: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
NUM_TO_STR: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
STR_TO_NUM: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
IS_NUM: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
ASC: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
CHR: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
INT: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
RAND: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
DAY: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
MONTH: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
YEAR: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
DAYINDEX: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
SETDATE: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
TODAY: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
EOF: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
ROUND: PreprocesssedBuiltinFunctionData<BuiltinFunctionArg[], "INTEGER" | "REAL" | "BOOLEAN" | "STRING" | "CHAR" | "DATE">;
};
export {};
2 changes: 1 addition & 1 deletion build/lexer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export declare const tokenNameTypeData: {
readonly ".": "punctuation.period";
readonly "\n": "newline";
};
export declare const tokenTextMapping: Record<"brace.open" | "brace.close" | "bracket.open" | "bracket.close" | "parentheses.open" | "parentheses.close" | "punctuation.colon" | "punctuation.semicolon" | "punctuation.comma" | "punctuation.period" | "boolean.true" | "boolean.false" | "keyword.declare" | "keyword.define" | "keyword.constant" | "keyword.output" | "keyword.input" | "keyword.call" | "keyword.if" | "keyword.then" | "keyword.else" | "keyword.if_end" | "keyword.for" | "keyword.to" | "keyword.for_end" | "keyword.step" | "keyword.while" | "keyword.while_end" | "keyword.dowhile" | "keyword.dowhile_end" | "keyword.function" | "keyword.function_end" | "keyword.procedure" | "keyword.procedure_end" | "keyword.return" | "keyword.returns" | "keyword.pass_mode.by_reference" | "keyword.pass_mode.by_value" | "keyword.type" | "keyword.type_end" | "keyword.open_file" | "keyword.read_file" | "keyword.write_file" | "keyword.close_file" | "keyword.get_record" | "keyword.put_record" | "keyword.seek" | "keyword.file_mode.read" | "keyword.file_mode.write" | "keyword.file_mode.append" | "keyword.file_mode.random" | "keyword.case" | "keyword.of" | "keyword.case_end" | "keyword.otherwise" | "keyword.class" | "keyword.class_end" | "keyword.new" | "keyword.super" | "keyword.inherits" | "keyword.class_modifier.private" | "keyword.class_modifier.public" | "keyword.array" | "keyword.set" | "keyword.end" | "newline" | "operator.add" | "operator.minus" | "operator.multiply" | "operator.divide" | "operator.mod" | "operator.integer_divide" | "operator.and" | "operator.or" | "operator.not" | "operator.equal_to" | "operator.not_equal_to" | "operator.less_than" | "operator.greater_than" | "operator.less_than_equal" | "operator.greater_than_equal" | "operator.assignment" | "operator.pointer" | "operator.string_concatenate" | "operator.range", "READ" | "WRITE" | "APPEND" | "RANDOM" | "\n" | "NEW" | "[" | "]" | "." | "AND" | "ARRAY" | "BYREF" | "BYVAL" | "CALL" | "CASE" | "CLASS" | "CLOSEFILE" | "CONSTANT" | "DECLARE" | "DEFINE" | "DIV" | "ELSE" | "END" | "ENDCASE" | "ENDCLASS" | "ENDFUNCTION" | "ENDIF" | "ENDPROCEDURE" | "ENDTYPE" | "ENDWHILE" | "FALSE" | "FOR" | "FUNCTION" | "GETRECORD" | "IF" | "INHERITS" | "INPUT" | "MOD" | "NEXT" | "NOT" | "OF" | "OPENFILE" | "OR" | "OTHERWISE" | "OUTPUT" | "PRIVATE" | "PROCEDURE" | "PUBLIC" | "PUTRECORD" | "READFILE" | "REPEAT" | "RETURN" | "RETURNS" | "SEEK" | "SET" | "STEP" | "SUPER" | "THEN" | "TO" | "TRUE" | "TYPE" | "UNTIL" | "WHILE" | "WRITEFILE" | "<-" | ">=" | "<=" | "<>" | ".." | "=" | ">" | "<" | "+" | "-" | "*" | "/" | "^" | "&" | "(" | ")" | "{" | "}" | ":" | ";" | ",">;
export declare const tokenTextMapping: Record<"brace.open" | "brace.close" | "bracket.open" | "bracket.close" | "parentheses.open" | "parentheses.close" | "punctuation.colon" | "punctuation.semicolon" | "punctuation.comma" | "punctuation.period" | "newline" | "operator.add" | "operator.minus" | "operator.multiply" | "operator.divide" | "operator.mod" | "operator.integer_divide" | "operator.and" | "operator.or" | "operator.not" | "operator.equal_to" | "operator.not_equal_to" | "operator.less_than" | "operator.greater_than" | "operator.less_than_equal" | "operator.greater_than_equal" | "operator.assignment" | "operator.pointer" | "operator.string_concatenate" | "operator.range" | "boolean.true" | "boolean.false" | "keyword.declare" | "keyword.define" | "keyword.constant" | "keyword.output" | "keyword.input" | "keyword.call" | "keyword.if" | "keyword.then" | "keyword.else" | "keyword.if_end" | "keyword.for" | "keyword.to" | "keyword.for_end" | "keyword.step" | "keyword.while" | "keyword.while_end" | "keyword.dowhile" | "keyword.dowhile_end" | "keyword.function" | "keyword.function_end" | "keyword.procedure" | "keyword.procedure_end" | "keyword.return" | "keyword.returns" | "keyword.pass_mode.by_reference" | "keyword.pass_mode.by_value" | "keyword.type" | "keyword.type_end" | "keyword.open_file" | "keyword.read_file" | "keyword.write_file" | "keyword.close_file" | "keyword.get_record" | "keyword.put_record" | "keyword.seek" | "keyword.file_mode.read" | "keyword.file_mode.write" | "keyword.file_mode.append" | "keyword.file_mode.random" | "keyword.case" | "keyword.of" | "keyword.case_end" | "keyword.otherwise" | "keyword.class" | "keyword.class_end" | "keyword.new" | "keyword.super" | "keyword.inherits" | "keyword.class_modifier.private" | "keyword.class_modifier.public" | "keyword.array" | "keyword.set" | "keyword.end", "\n" | ">=" | "<=" | "<>" | ".." | "=" | ">" | "<" | "+" | "-" | "*" | "/" | "^" | "&" | "(" | ")" | "[" | "]" | "{" | "}" | ":" | ";" | "," | "." | "AND" | "APPEND" | "ARRAY" | "BYREF" | "BYVAL" | "CALL" | "CASE" | "CLASS" | "CLOSEFILE" | "CONSTANT" | "DECLARE" | "DEFINE" | "DIV" | "ELSE" | "END" | "ENDCASE" | "ENDCLASS" | "ENDFUNCTION" | "ENDIF" | "ENDPROCEDURE" | "ENDTYPE" | "ENDWHILE" | "FALSE" | "FOR" | "FUNCTION" | "GETRECORD" | "IF" | "INHERITS" | "INPUT" | "MOD" | "NEW" | "NEXT" | "NOT" | "OF" | "OPENFILE" | "OR" | "OTHERWISE" | "OUTPUT" | "PRIVATE" | "PROCEDURE" | "PUBLIC" | "PUTRECORD" | "RANDOM" | "READ" | "READFILE" | "REPEAT" | "RETURN" | "RETURNS" | "SEEK" | "SET" | "STEP" | "SUPER" | "THEN" | "TO" | "TRUE" | "TYPE" | "UNTIL" | "WHILE" | "WRITE" | "WRITEFILE" | "<-">;
type SymbolSpecifierFuncName = "isAlphanumeric" | "isNumber";
export declare function symbolize(input: string): SymbolizedProgram;
export declare function tokenize(input: SymbolizedProgram): TokenizedProgram;
Expand Down
2 changes: 1 addition & 1 deletion build/parser-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export type PreprocessedOperator = {
type?: OperatorMode;
};
export declare const operatorsByPriority: Operator[][];
export declare const operators: Record<OperatorType, Operator>;
export declare const operators: Record<"add" | "negate" | "subtract" | "access" | "pointer_reference" | "pointer_dereference" | "multiply" | "divide" | "mod" | "integer_divide" | "and" | "or" | "not" | "equal_to" | "not_equal_to" | "less_than" | "greater_than" | "less_than_equal" | "greater_than_equal" | "string_concatenate", Operator>;
export type TokenMatcher = TokenType | "." | "literal" | "literal|otherwise" | ".*" | ".+" | "expr+" | "type+" | "file_mode" | "class_modifier";
export type ProgramAST = {
program: string;
Expand Down
19 changes: 15 additions & 4 deletions build/runtime-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ declare class TypedValue_<T extends VariableType> {
asHTML(recursive: boolean): string;
asString(): string;
}
export declare const TypedValue: { [N in PrimitiveVariableTypeName]: (value: VariableTypeMapping<PrimitiveVariableType<N>>) => TypedValue_<PrimitiveVariableType<N>>; };
export declare const TypedValue: {
INTEGER: (value: number) => TypedValue_<PrimitiveVariableType<"INTEGER">>;
REAL: (value: number) => TypedValue_<PrimitiveVariableType<"REAL">>;
BOOLEAN: (value: boolean) => TypedValue_<PrimitiveVariableType<"BOOLEAN">>;
STRING: (value: string) => TypedValue_<PrimitiveVariableType<"STRING">>;
CHAR: (value: string) => TypedValue_<PrimitiveVariableType<"CHAR">>;
DATE: (value: Date) => TypedValue_<PrimitiveVariableType<"DATE">>;
};
export declare function typedValue<T extends VariableType>(type: T, value: VariableTypeMapping<T>): TypedValue;
export declare abstract class BaseVariableType implements IFormattable {
abstract getInitValue(runtime: Runtime, requireInit: boolean): unknown;
Expand Down Expand Up @@ -178,10 +185,14 @@ export declare class ClassVariableType<Init extends boolean = true> extends Base
inherits(other: ClassVariableType): boolean;
construct(runtime: Runtime, args: RangeArray<ExpressionASTNode>): {
properties: {
[index: string]: VariableTypeMapping<any> | null;
[index: string]: string | number | boolean | Date | (string | number | boolean | Date | {
[index: string]: string | number | boolean | Date | (string | number | boolean | Date | any | VariableData<VariableType<true>, null> | ConstantData<VariableType<true>> | any | null)[] | any | VariableData<VariableType<true>, null> | ConstantData<VariableType<true>> | (string | number | boolean | Date)[] | any | null;
} | VariableData<VariableType<true>, null> | ConstantData<VariableType<true>> | any | null)[] | {
[index: string]: string | number | boolean | Date | (string | number | boolean | Date | any | VariableData<VariableType<true>, null> | ConstantData<VariableType<true>> | any | null)[] | any | VariableData<VariableType<true>, null> | ConstantData<VariableType<true>> | (string | number | boolean | Date)[] | any | null;
} | VariableData<VariableType<true>, null> | ConstantData<VariableType<true>> | (string | number | boolean | Date)[] | any | null;
};
propertyTypes: Record<string, VariableType>;
type: ClassVariableType;
propertyTypes: Record<string, VariableType<true>>;
type: ClassVariableType<true>;
};
getScope(runtime: Runtime, instance: VariableTypeMapping<ClassVariableType>): VariableScope;
iterateProperties<T>(value: VariableTypeMapping<ClassVariableType>, callback: (tval: TypedValue | null, name: string, statement: ClassPropertyStatement) => T): T[];
Expand Down
2 changes: 1 addition & 1 deletion build/runtime-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function typedValue(type, value) {
if (type == null || value == null)
impossible();
if (!(type instanceof BaseVariableType)) {
type;
(type);
crash(`Type was not a valid type`, type);
}
return new TypedValue_(type, value);
Expand Down
10 changes: 5 additions & 5 deletions build/runtime.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ export declare class Runtime {
evaluateToken(token: Token, type: "function"): FunctionData | BuiltinFunctionData;
evaluateToken<T extends VariableType | undefined>(token: Token, type: T): TypedValue<T extends undefined ? VariableType : T & {}>;
static NotStaticError: {
new (message?: string): {
new (message?: string | undefined): {
name: string;
message: string;
stack?: string;
stack?: string | undefined;
cause?: unknown;
};
new (message?: string, options?: ErrorOptions): {
new (message?: string | undefined, options?: ErrorOptions | undefined): {
name: string;
message: string;
stack?: string;
stack?: string | undefined;
cause?: unknown;
};
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
stackTraceLimit: number;
};
Expand Down
2 changes: 1 addition & 1 deletion build/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ value ${indexes[invalidIndexIndex][1]} was not in range \
if (outType == "variable") {
return {
type: outputType,
declaration: target.declaration,
declaration: (target).declaration,
mutable: true,
get value() { return targetValue[property]; },
set value(val) { targetValue[property] = val; }
Expand Down
Loading

0 comments on commit ba94bd1

Please sign in to comment.