Skip to content

Commit

Permalink
update tests & Fix issues with html tags
Browse files Browse the repository at this point in the history
  • Loading branch information
armano2 committed Oct 22, 2018
1 parent 25161c5 commit 995f240
Show file tree
Hide file tree
Showing 15 changed files with 348 additions and 33 deletions.
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jobs:
- run:
name: Test
command: npm test
- store_test_results:
path: test-results
- save_cache:
key: v2-npm-lock-{{ .Branch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "package-lock.json" }}
paths:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ lib-cov
# Coverage directory used by tools like istanbul
coverage

# unit
test-results

# nyc test coverage
.nyc_output

Expand Down
139 changes: 117 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
"scripts": {
"build": "npm run lint & tsc",
"pretest": "npm run build",
"mocha": "nyc mocha \"test/*.ts\"",
"mocha": "nyc mocha \"test/*.ts\" --reporter=mocha-junit-reporter --reporter-options mochaFile=./test-results/mocha/results.xml",
"test": "npm run mocha",
"posttest": "nyc report --reporter=lcovonly && codecov -f coverage/*.info",
"lint": "tslint '**/*.ts'",
"lint-fix": "tslint '**/*.ts' --fix",
"update-ast": "npm run build & node ./scripts/update-ast.js",
"watch": "tsc --watch",
"coverage": "npm run mocha && nyc report --reporter html"
"coverage": "nyc mocha \"test/*.ts\" && nyc report --reporter html"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -41,14 +41,15 @@
],
"homepage": "https://github.com/armano2/freemarker-parser#readme",
"devDependencies": {
"@types/glob": "^7.1.1",
"@types/json-stringify-safe": "^5.0.0",
"@types/mocha": "^5.2.5",
"@types/node": "^10.12.0",
"codecov": "^3.1.0",
"glob": "^7.1.3",
"mocha": "^5.2.0",
"nyc": "^13.1.0",
"source-map-support": "^0.5.9",
"tiny-glob": "^0.2.2",
"ts-node": "^7.0.1",
"tslint": "^5.11.0",
"typescript": "^3.1.3"
Expand Down
5 changes: 3 additions & 2 deletions scripts/update-ast.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const freemarker = require('../dist/index')
const fs = require('fs')
const path = require('path')
const glob = require('tiny-glob')
const util = require('util')
const glob = util.promisify(require('glob'));

const parser = new freemarker.Parser()

Expand All @@ -11,7 +12,7 @@ function stringify (text) {
return JSON.stringify(text, null, 2)
}

glob('./**/*.ftl', { cwd: rootDir, filesOnly: true, absolute: true })
glob('./**/*.ftl', { cwd: rootDir, nodir: true, absolute: true })
.then((files) => {
for (const file of files) {
fs.readFile(file, 'utf8', (err, template) => {
Expand Down
2 changes: 1 addition & 1 deletion src/Tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class Tokenizer {
let startPos : number = 0
for (const item of symbols) {
const n = this.template.indexOf(item.startToken, this.cursorPos)
if (n >= 0 && (!symbol || n < startPos)) {
if (n === this.cursorPos && (!symbol || n < startPos)) {
symbol = item
startPos = n
}
Expand Down
6 changes: 4 additions & 2 deletions test/parser-invalid.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import * as assert from 'assert'
import * as fs from 'fs'
import * as path from 'path'
import glob = require('tiny-glob')
import { promisify } from 'util'
import { Parser } from '../src/index'

const parser = new Parser()
// tslint:disable-next-line
const glob = promisify(require('glob'))

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

function cleanup (data : any) {
return JSON.parse(JSON.stringify(data))
}

glob('./**/*.ftl', { cwd: testsPath, filesOnly: true, absolute: true })
glob('./**/*.ftl', { cwd: testsPath, nodir: true, absolute: true })
.then((files : string[]) => {
for (const file of files) {
describe(file, () => {
Expand Down
6 changes: 4 additions & 2 deletions test/parser-valid.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import * as assert from 'assert'
import * as fs from 'fs'
import * as path from 'path'
import glob = require('tiny-glob')
import { promisify } from 'util'
import { Parser } from '../src/index'

const parser = new Parser()
// tslint:disable-next-line
const glob = promisify(require('glob'))

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

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

glob('./**/*.ftl', { cwd: testsPath, filesOnly: true, absolute: true })
glob('./**/*.ftl', { cwd: testsPath, nodir: true, absolute: true })
.then((files : string[]) => {
for (const file of files) {
describe(file, () => {
Expand Down
14 changes: 13 additions & 1 deletion test/resource/valid/comment-ast.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": "Program",
"start": 0,
"end": 98,
"end": 130,
"body": [
{
"type": "Comment",
Expand Down Expand Up @@ -63,6 +63,18 @@
"start": 97,
"end": 98,
"text": "\n"
},
{
"type": "Comment",
"start": 98,
"end": 129,
"text": "\nTest comment\nmultiline\n"
},
{
"type": "Text",
"start": 129,
"end": 130,
"text": "\n"
}
]
}
16 changes: 16 additions & 0 deletions test/resource/valid/comment-tokens.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,21 @@
"end": 98,
"text": "\n",
"isClose": false
},
{
"type": "Comment",
"start": 98,
"end": 129,
"startTag": "<#--",
"endTag": "-->",
"text": "\nTest comment\nmultiline\n",
"isClose": false
},
{
"type": "Text",
"start": 129,
"end": 130,
"text": "\n",
"isClose": false
}
]
Loading

0 comments on commit 995f240

Please sign in to comment.