forked from github-mirror/twing
Update tests, fix functions after Locutus removal
This commit is contained in:
parent
8f8a6786fe
commit
4c0fbd9572
src
main/lib
escaping-stragegy
extension/core
helpers
test/tests
integration
unit
lib.ts
lib
environment
error
helpers
asort
chunk
compare
count
examine-object
fill-map
format-date-time
format-duration
iconv
includes
is-in
iterate
iterator-to-array
iterator-to-hash
iterator-to-map
ksort
modify-date
reverse
slice
lexer
loader
node-executor
node-traverser
output-buffer
parser/create-parser
template-loader
template
@ -1,5 +1,5 @@
|
||||
import {TwingEscapingStrategyHandler} from "../escaping-strategy";
|
||||
|
||||
export const createUrlEscapingStrategyHandler = (): TwingEscapingStrategyHandler => {
|
||||
return (value) => encodeURIComponent(value);
|
||||
return (value) => encodeURIComponent(value).replace("'", '%27').replace('!', '%21');
|
||||
};
|
||||
|
@ -7,6 +7,6 @@ export const nl2brSynchronously: TwingSynchronousCallable = (
|
||||
value: string,
|
||||
useXHTML: boolean = true
|
||||
): TwingMarkup => {
|
||||
const replaceWith = useXHTML ? "<br />" : "<br>";
|
||||
const replaceWith = useXHTML ? "<br />\n" : "<br>\n";
|
||||
return createMarkup(value.replace(/\r\n|\n\r|\r|\n/g, replaceWith));
|
||||
};
|
||||
|
@ -13,10 +13,11 @@ export const urlEncodeSynchronously: TwingSynchronousCallable = (_executionConte
|
||||
if (typeof url !== 'string') {
|
||||
if (isTraversable(url)) {
|
||||
url = iteratorToHash(url);
|
||||
const params = new URLSearchParams(url)
|
||||
return params.toString().replace('+', '%20')
|
||||
} else {
|
||||
return ''
|
||||
}
|
||||
|
||||
const params = new URLSearchParams(url)
|
||||
return params.toString()
|
||||
}
|
||||
|
||||
return encodeURIComponent(url);
|
||||
|
@ -8,5 +8,16 @@ export const maxSynchronously: TwingSynchronousCallable<[
|
||||
values = values[0];
|
||||
}
|
||||
|
||||
return Math.max(...iteratorToArray(values));
|
||||
const arr = iteratorToArray(values)
|
||||
if (typeof arr[0] === 'number') {
|
||||
return Math.max(...arr);
|
||||
} else {
|
||||
let maxIndex = 0;
|
||||
for (let i = 1; i < arr.length; i++) {
|
||||
if (String(arr[i]).localeCompare(arr[maxIndex]) === 1) {
|
||||
maxIndex = i
|
||||
}
|
||||
}
|
||||
return arr[maxIndex]
|
||||
}
|
||||
};
|
||||
|
@ -8,5 +8,16 @@ export const minSynchronously: TwingSynchronousCallable<[
|
||||
values = values[0];
|
||||
}
|
||||
|
||||
return Math.min(...iteratorToArray(values));
|
||||
const arr = iteratorToArray(values)
|
||||
if (typeof arr[0] === 'number') {
|
||||
return Math.min(...arr);
|
||||
} else {
|
||||
let minIndex = 0;
|
||||
for (let i = 1; i < arr.length; i++) {
|
||||
if (String(arr[i]).localeCompare(arr[minIndex]) === -1) {
|
||||
minIndex = i
|
||||
}
|
||||
}
|
||||
return arr[minIndex]
|
||||
}
|
||||
};
|
||||
|
@ -1,17 +1,20 @@
|
||||
import type {TwingBaseArrayNode} from "../node/expression/array";
|
||||
import {TwingConstantNode} from "../node/expression/constant";
|
||||
import {TwingBaseExpressionNode} from "../node/expression";
|
||||
import type { TwingBaseArrayNode } from "../node/expression/array";
|
||||
import { TwingConstantNode } from "../node/expression/constant";
|
||||
import { TwingBaseExpressionNode } from "../node/expression";
|
||||
|
||||
export const getKeyValuePairs = (
|
||||
node: TwingBaseArrayNode<any>
|
||||
): Array<{
|
||||
key: TwingConstantNode,
|
||||
value: TwingBaseExpressionNode
|
||||
key: TwingConstantNode;
|
||||
value: TwingBaseExpressionNode;
|
||||
}> => {
|
||||
const values = Object.values(node)
|
||||
const result = []
|
||||
const values = Object.values(node.children);
|
||||
const result = [];
|
||||
for (let i = 0; i < values.length; i += 2) {
|
||||
result.push({ key: values[i], value: values[i + 1] })
|
||||
result.push({
|
||||
key: values[i] as TwingConstantNode,
|
||||
value: values[i + 1] as TwingBaseExpressionNode,
|
||||
});
|
||||
}
|
||||
return result
|
||||
return result;
|
||||
};
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from 'tape';
|
||||
import tape from 'tape';
|
||||
import {SinonStub, stub} from 'sinon';
|
||||
import {
|
||||
createSynchronousEnvironment,
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from 'tape';
|
||||
import tape from 'tape';
|
||||
import * as index from "../../../main/lib";
|
||||
|
||||
tape('library index', ({same, end}) => {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from "tape";
|
||||
import tape from "tape";
|
||||
import {createSynchronousEnvironment} from "../../../../../main/lib/environment";
|
||||
import {createSynchronousArrayLoader} from "../../../../../main/lib/loader/array";
|
||||
import {Settings} from "luxon";
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from "tape";
|
||||
import tape from "tape";
|
||||
import {createSynchronousEnvironment} from "../../../../../main/lib/environment";
|
||||
import {createSynchronousArrayLoader} from "../../../../../main/lib/loader/array";
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from "tape";
|
||||
import tape from "tape";
|
||||
import {createBaseError} from "../../../../../../main/lib/error/base";
|
||||
|
||||
tape('createBaseError', ({test}) => {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from "tape";
|
||||
import tape from "tape";
|
||||
import {createRuntimeError} from "../../../../../../main/lib/error/runtime";
|
||||
|
||||
tape('createRuntimeError', ({test}) => {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from 'tape';
|
||||
import tape from 'tape';
|
||||
import {asortSynchronously} from "../../../../../../main/lib/helpers/asort";
|
||||
|
||||
tape('asort', (test) => {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from 'tape';
|
||||
import tape from 'tape';
|
||||
import {chunk} from "../../../../../../main/lib/helpers/chunk";
|
||||
|
||||
tape('chunk', (test) => {
|
||||
|
@ -2,7 +2,7 @@ import {compare} from "../../../../../../main/lib/helpers/compare";
|
||||
|
||||
const {DateTime} = require('luxon');
|
||||
|
||||
import * as tape from 'tape';
|
||||
import tape from 'tape';
|
||||
|
||||
let booleanTrue = ['true', true];
|
||||
let booleanFalse = ['false', false];
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from 'tape';
|
||||
import tape from 'tape';
|
||||
import {count} from "../../../../../../main/lib/helpers/count";
|
||||
|
||||
tape('count', (test) => {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from 'tape';
|
||||
import tape from 'tape';
|
||||
import {examineObject} from "../../../../../../main/lib/helpers/examine-object";
|
||||
|
||||
class Foo {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from 'tape';
|
||||
import tape from 'tape';
|
||||
import {fillMap} from "../../../../../../main/lib/helpers/fill-map";
|
||||
|
||||
tape('fillMap', (test) => {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from 'tape';
|
||||
import tape from 'tape';
|
||||
import {formatDateTime} from "../../../../../../main/lib/helpers/format-date-time";
|
||||
|
||||
const {DateTime, Settings} = require('luxon');
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from "tape";
|
||||
import tape from "tape";
|
||||
import {Duration} from "luxon";
|
||||
import {formatDuration} from "../../../../../../main/lib/helpers/format-duration";
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from 'tape';
|
||||
import tape from 'tape';
|
||||
import {iconv} from "../../../../../../main/lib/helpers/iconv";
|
||||
|
||||
tape('iconv', ({test}) => {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from 'tape';
|
||||
import tape from 'tape';
|
||||
import {includes} from "../../../../../../main/lib/helpers/includes";
|
||||
|
||||
tape('includes', (test) => {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from 'tape';
|
||||
import tape from 'tape';
|
||||
import {isIn} from "../../../../../../main/lib/helpers/is-in";
|
||||
|
||||
tape('is-in', ({same, end}) => {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from 'tape';
|
||||
import tape from 'tape';
|
||||
import {iterate} from "../../../../../../main/lib/helpers/iterate";
|
||||
|
||||
class TestIterator {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from 'tape';
|
||||
import tape from 'tape';
|
||||
import {iteratorToArray} from "../../../../../../main/lib/helpers/iterator-to-array";
|
||||
|
||||
class TestIterator {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from 'tape';
|
||||
import tape from 'tape';
|
||||
import {iteratorToHash} from "../../../../../../main/lib/helpers/iterator-to-hash";
|
||||
|
||||
class Foo {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from 'tape';
|
||||
import tape from 'tape';
|
||||
import {iteratorToMap} from "../../../../../../main/lib/helpers/iterator-to-map";
|
||||
|
||||
const createIterator = () => {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from 'tape';
|
||||
import tape from 'tape';
|
||||
import {ksort} from "../../../../../../main/lib/helpers/ksort";
|
||||
|
||||
tape('ksort', (test) => {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from 'tape';
|
||||
import tape from 'tape';
|
||||
import {modifyDate} from "../../../../../../main/lib/helpers/modify-date";
|
||||
|
||||
const sinon = require('sinon');
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from 'tape';
|
||||
import tape from 'tape';
|
||||
import {reverse} from "../../../../../../main/lib/helpers/reverse";
|
||||
|
||||
tape('reverse', (test) => {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from 'tape';
|
||||
import tape from 'tape';
|
||||
import {sliceMap} from "../../../../../../main/lib/helpers/slice-map";
|
||||
|
||||
tape('slice', (test) => {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from 'tape';
|
||||
import tape from 'tape';
|
||||
import {createLexer, typeToEnglish} from "../../../../../main/lib/lexer";
|
||||
import {createOperator} from "../../../../../main/lib/operator";
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from 'tape';
|
||||
import tape from 'tape';
|
||||
import {createArrayLoader, createSynchronousArrayLoader} from "../../../../../../main/lib/loader/array";
|
||||
|
||||
tape('createArrayLoader', ({test}) => {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from 'tape';
|
||||
import tape from 'tape';
|
||||
import {createChainLoader, createSynchronousChainLoader} from "../../../../../../main/lib/loader/chain";
|
||||
import {createArrayLoader, createSynchronousArrayLoader} from "../../../../../../main/lib/loader/array";
|
||||
import {spy, stub} from "sinon";
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from "tape";
|
||||
import tape from "tape";
|
||||
import {
|
||||
createFilesystemLoader,
|
||||
createSynchronousFilesystemLoader,
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from "tape";
|
||||
import tape from "tape";
|
||||
import {createBaseNode} from "../../../../../../main/lib/node";
|
||||
import {executeNodeSynchronously} from "../../../../../../main/lib/node-executor";
|
||||
import type {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from "tape";
|
||||
import tape from "tape";
|
||||
import {
|
||||
executeBinaryNodeSynchronously
|
||||
} from "../../../../../../main/lib/node-executor/expression/binary";
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from "tape";
|
||||
import tape from "tape";
|
||||
import {createConstantNode} from "../../../../../../main/lib/node/expression/constant";
|
||||
import {
|
||||
executeUnaryNodeSynchronously
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from 'tape';
|
||||
import tape from 'tape';
|
||||
import {createNodeTraverser} from "../../../../../main/lib/node-traverser";
|
||||
import {TwingBaseNode, createBaseNode} from "../../../../../main/lib/node";
|
||||
import {createNodeVisitor, TwingNodeVisitor} from "../../../../../main/lib/node-visitor";
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from 'tape';
|
||||
import tape from 'tape';
|
||||
import {createOutputBuffer} from "../../../../../main/lib/output-buffer";
|
||||
import {spy} from "sinon";
|
||||
import {Writable} from "stream";
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from "tape";
|
||||
import tape from "tape";
|
||||
import {createParser} from "../../../../../../main/lib/parser";
|
||||
import {createSource} from "../../../../../../main/lib/source";
|
||||
import {createLexer} from "../../../../../../main/lib/lexer";
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from "tape";
|
||||
import tape from "tape";
|
||||
import {createSynchronousEnvironment} from "../../../../../main/lib/environment";
|
||||
import {
|
||||
createSynchronousFilesystemLoader,
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from "tape";
|
||||
import tape from "tape";
|
||||
import {createSynchronousEnvironment} from "../../../../../main/lib/environment";
|
||||
import {createSynchronousArrayLoader} from "../../../../../main/lib/loader/array";
|
||||
import {TwingTemplateNode} from "../../../../../main/lib/node/template";
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from "tape";
|
||||
import tape from "tape";
|
||||
import {createSynchronousTemplate} from "../../../../../main/lib/template";
|
||||
import {createTemplateNode} from "../../../../../main/lib/node/template";
|
||||
import {createBaseNode} from "../../../../../main/lib/node";
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { spy } from "sinon";
|
||||
import * as tape from "tape";
|
||||
import tape from "tape";
|
||||
import {createSynchronousEnvironment} from "../../../../../main/lib/environment";
|
||||
import {createSynchronousArrayLoader} from "../../../../../main/lib/loader/array";
|
||||
import {createBaseNode} from "../../../../../main/lib/node";
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as tape from "tape";
|
||||
import tape from "tape";
|
||||
import {createSynchronousEnvironment} from "../../../../../main/lib/environment";
|
||||
import {createSynchronousArrayLoader} from "../../../../../main/lib/loader/array";
|
||||
import {createSynchronousTemplate} from "../../../../../main/lib/template";
|
||||
|
Loading…
x
Reference in New Issue
Block a user