import 'mocha' import { expect } from 'chai' import { RelativeDateFormatLexer } from '../lib/lexer-parser/RelativeDateFormatLexer'; import { getTokenListFromString } from './helpers'; describe("Tokenization tests", function() { var passing_runs = [ { rdf: "$range$", desc: "range token", tokens: [ RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.RANGE, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.EOF ] }, { rdf: "$trail$", desc: "trail token", tokens: [ RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.TRAIL, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.EOF ] }, { rdf: "$period$", desc: "period token", tokens: [ RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.PERIOD, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.EOF ] }, { rdf: "$range$0$0$", desc: "epoch to epoch", tokens: [ RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.RANGE, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.EOF ] }, { rdf: "$range$1020$174398127390$", desc: "long numbers", tokens: [ RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.RANGE, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.EOF ] }, { rdf: "$range$0$now$", desc: "epoch to now", tokens: [ RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.RANGE, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.NOW, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.EOF ] }, { rdf: "$range$now$now$", desc: "now to now", tokens: [ RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.RANGE, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.NOW, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.NOW, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.EOF ] }, { rdf: "$range$0-1s$0+1s$", desc: "second offsets", tokens: [ RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.RANGE, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.OP_MIN, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.SECONDS, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.OP_ADD, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.SECONDS, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.EOF ] }, { rdf: "$range$0-1m$0+1m$", desc: "minute offsets", tokens: [ RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.RANGE, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.OP_MIN, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.MINUTES, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.OP_ADD, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.MINUTES, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.EOF ] }, { rdf: "$range$0-1h$0+1h$", desc: "hour offsets", tokens: [ RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.RANGE, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.OP_MIN, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.HOURS, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.OP_ADD, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.HOURS, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.EOF ] }, { rdf: "$range$0-1d$0+1d$", desc: "day offsets", tokens: [ RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.RANGE, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.OP_MIN, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.DAYS, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.OP_ADD, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.DAYS, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.EOF ] }, { rdf: "$range$0-1w$0+1w$", desc: "week offsets", tokens: [ RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.RANGE, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.OP_MIN, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.WEEKS, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.OP_ADD, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.WEEKS, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.EOF ] }, { rdf: "$range$0-1M$0+1M$", desc: "month offsets", tokens: [ RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.RANGE, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.OP_MIN, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.MONTHS, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.OP_ADD, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.MONTHS, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.EOF ] }, { rdf: "$range$0-1Q$0+1Q$", desc: "quarter offsets", tokens: [ RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.RANGE, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.OP_MIN, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.QUARTERS, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.OP_ADD, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.QUARTERS, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.EOF ] }, { rdf: "$range$0-1Y$0+1Y$", desc: "year offsets", tokens: [ RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.RANGE, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.OP_MIN, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.YEARS, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.OP_ADD, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.YEARS, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.EOF ] }, { rdf: "$range$0-1s+1m$0+1s-1m$", desc: "composite static offsets", tokens: [ RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.RANGE, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.OP_MIN, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.SECONDS, RelativeDateFormatLexer.OP_ADD, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.MINUTES, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.OP_ADD, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.SECONDS, RelativeDateFormatLexer.OP_MIN, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.MINUTES, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.EOF ] }, { rdf: "$range$0-1s+1M$0+1s-1M$", desc: "composite static/relative offsets", tokens: [ RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.RANGE, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.OP_MIN, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.SECONDS, RelativeDateFormatLexer.OP_ADD, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.MONTHS, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.OP_ADD, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.SECONDS, RelativeDateFormatLexer.OP_MIN, RelativeDateFormatLexer.NUMBER, RelativeDateFormatLexer.MONTHS, RelativeDateFormatLexer.SEPERATOR, RelativeDateFormatLexer.EOF ] } ] for(let run of passing_runs) { it(`${run.rdf.replace(/\n/g,"\\n")}: ${run.desc} should tokenize`, function(){ expect(getTokenListFromString(run.rdf)).to.be.eql(run.tokens) }) } })