Skip to content

Commit 995f240

Browse files
committed
update tests & Fix issues with html tags
1 parent 25161c5 commit 995f240

File tree

15 files changed

+348
-33
lines changed

15 files changed

+348
-33
lines changed

.circleci/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ jobs:
2828
- run:
2929
name: Test
3030
command: npm test
31+
- store_test_results:
32+
path: test-results
3133
- save_cache:
3234
key: v2-npm-lock-{{ .Branch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "package-lock.json" }}
3335
paths:

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ lib-cov
1919
# Coverage directory used by tools like istanbul
2020
coverage
2121

22+
# unit
23+
test-results
24+
2225
# nyc test coverage
2326
.nyc_output
2427

package-lock.json

Lines changed: 117 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
"scripts": {
66
"build": "npm run lint & tsc",
77
"pretest": "npm run build",
8-
"mocha": "nyc mocha \"test/*.ts\"",
8+
"mocha": "nyc mocha \"test/*.ts\" --reporter=mocha-junit-reporter --reporter-options mochaFile=./test-results/mocha/results.xml",
99
"test": "npm run mocha",
1010
"posttest": "nyc report --reporter=lcovonly && codecov -f coverage/*.info",
1111
"lint": "tslint '**/*.ts'",
1212
"lint-fix": "tslint '**/*.ts' --fix",
1313
"update-ast": "npm run build & node ./scripts/update-ast.js",
1414
"watch": "tsc --watch",
15-
"coverage": "npm run mocha && nyc report --reporter html"
15+
"coverage": "nyc mocha \"test/*.ts\" && nyc report --reporter html"
1616
},
1717
"repository": {
1818
"type": "git",
@@ -41,14 +41,15 @@
4141
],
4242
"homepage": "https://github.com/armano2/freemarker-parser#readme",
4343
"devDependencies": {
44+
"@types/glob": "^7.1.1",
4445
"@types/json-stringify-safe": "^5.0.0",
4546
"@types/mocha": "^5.2.5",
4647
"@types/node": "^10.12.0",
4748
"codecov": "^3.1.0",
49+
"glob": "^7.1.3",
4850
"mocha": "^5.2.0",
4951
"nyc": "^13.1.0",
5052
"source-map-support": "^0.5.9",
51-
"tiny-glob": "^0.2.2",
5253
"ts-node": "^7.0.1",
5354
"tslint": "^5.11.0",
5455
"typescript": "^3.1.3"

scripts/update-ast.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
const freemarker = require('../dist/index')
22
const fs = require('fs')
33
const path = require('path')
4-
const glob = require('tiny-glob')
4+
const util = require('util')
5+
const glob = util.promisify(require('glob'));
56

67
const parser = new freemarker.Parser()
78

@@ -11,7 +12,7 @@ function stringify (text) {
1112
return JSON.stringify(text, null, 2)
1213
}
1314

14-
glob('./**/*.ftl', { cwd: rootDir, filesOnly: true, absolute: true })
15+
glob('./**/*.ftl', { cwd: rootDir, nodir: true, absolute: true })
1516
.then((files) => {
1617
for (const file of files) {
1718
fs.readFile(file, 'utf8', (err, template) => {

src/Tokenizer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export class Tokenizer {
7171
let startPos : number = 0
7272
for (const item of symbols) {
7373
const n = this.template.indexOf(item.startToken, this.cursorPos)
74-
if (n >= 0 && (!symbol || n < startPos)) {
74+
if (n === this.cursorPos && (!symbol || n < startPos)) {
7575
symbol = item
7676
startPos = n
7777
}

test/parser-invalid.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import * as assert from 'assert'
22
import * as fs from 'fs'
33
import * as path from 'path'
4-
import glob = require('tiny-glob')
4+
import { promisify } from 'util'
55
import { Parser } from '../src/index'
66

77
const parser = new Parser()
8+
// tslint:disable-next-line
9+
const glob = promisify(require('glob'))
810

911
const testsPath = path.join(__dirname, 'resource', 'invalid')
1012

1113
function cleanup (data : any) {
1214
return JSON.parse(JSON.stringify(data))
1315
}
1416

15-
glob('./**/*.ftl', { cwd: testsPath, filesOnly: true, absolute: true })
17+
glob('./**/*.ftl', { cwd: testsPath, nodir: true, absolute: true })
1618
.then((files : string[]) => {
1719
for (const file of files) {
1820
describe(file, () => {

test/parser-valid.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import * as assert from 'assert'
22
import * as fs from 'fs'
33
import * as path from 'path'
4-
import glob = require('tiny-glob')
4+
import { promisify } from 'util'
55
import { Parser } from '../src/index'
66

77
const parser = new Parser()
8+
// tslint:disable-next-line
9+
const glob = promisify(require('glob'))
810

911
const baseDir = path.join(__dirname, '..')
1012

@@ -14,7 +16,7 @@ function cleanup (data : any) {
1416
return JSON.parse(JSON.stringify(data))
1517
}
1618

17-
glob('./**/*.ftl', { cwd: testsPath, filesOnly: true, absolute: true })
19+
glob('./**/*.ftl', { cwd: testsPath, nodir: true, absolute: true })
1820
.then((files : string[]) => {
1921
for (const file of files) {
2022
describe(file, () => {

test/resource/valid/comment-ast.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"type": "Program",
33
"start": 0,
4-
"end": 98,
4+
"end": 130,
55
"body": [
66
{
77
"type": "Comment",
@@ -63,6 +63,18 @@
6363
"start": 97,
6464
"end": 98,
6565
"text": "\n"
66+
},
67+
{
68+
"type": "Comment",
69+
"start": 98,
70+
"end": 129,
71+
"text": "\nTest comment\nmultiline\n"
72+
},
73+
{
74+
"type": "Text",
75+
"start": 129,
76+
"end": 130,
77+
"text": "\n"
6678
}
6779
]
6880
}

test/resource/valid/comment-tokens.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,21 @@
6363
"end": 98,
6464
"text": "\n",
6565
"isClose": false
66+
},
67+
{
68+
"type": "Comment",
69+
"start": 98,
70+
"end": 129,
71+
"startTag": "<#--",
72+
"endTag": "-->",
73+
"text": "\nTest comment\nmultiline\n",
74+
"isClose": false
75+
},
76+
{
77+
"type": "Text",
78+
"start": 129,
79+
"end": 130,
80+
"text": "\n",
81+
"isClose": false
6682
}
6783
]

0 commit comments

Comments
 (0)