<commit_before>const assert = require('assert')
const lexer = require('../lib/lexer.js')
const parser = require('../lib/parser.js')
const linker = require('../lib/linker.js')
const compiler = require('../lib/compiler.js')
const util = require('../lib/util.js')
const runtime = require('../lib/runtime.js')
const omelet = require('../lib/omelet.js')

function omeletToHtml(input, context, options) {
    context = context || {}
    options = options || {}
    const tokens = lexer.lex(input, options),
        ast = parser.parse(tokens, options),
        linkedAst = linker.link(ast, options),
        template = compiler.compile(linkedAst, options)
    return template(context)
}

describe('Tags', function() {
    const context = {}
    const options = {}

    const examples = [
        {
            name: 'plain tag',
            input: '@h1 hello, world!',
            output: '<h1>hello, world!</h1>'
        },
        {
            name: 'several tags',
            input: '@h1 hello, world!\n@h2 hi!\n@h3 this is omelet',
            output: '<h1>hello, world!</h1>\n<h2>hi!</h2>\n<h3>this is omelet</h3>'
        },
        {
            name: 'tags with attributes',
            input: '@a#anchor.className[href="#" target="_blank"] click me',
            output: '<a class="className" id="anchor" href="#" target="_blank">click me</a>'
        },
        {
            name: 'tags with multiple class attributes',
            input: '@h1.classOne#idName.classTwo hello, world!',
            output: '<h1 class="classOne classTwo" id="idName">hello, world!</h1>'
        },
        {
            name: 'tags with boolean attributes',
            input: '@input[type=checkbox checked]',
            output: '<input type="checkbox" checked="checked"/>'
        },
        {
            name: 'multitags',
            input: '@b|i.classy|u testing',
            output: '<b><i class="classy"><u>testing</u></i></b>'
        },
        {
            name: 'nested block tags',
            input: '@div\n  @div\n    @h1 hello!\n  @div\n    @h2 hello!',
            output: '<div>\n    <div>\n        <h1>hello!</h1>\n    </div>\n    <div>\n        <h2>hello!</h2>\n    </div>\n</div>'
        }
    ]

    examples.forEach(function(example) {
        it('translates ' + example.name, function() {
            assert.equal(omeletToHtml(example.input, context, options), example.output)
        })
    })

    const bad_examples = [
        {
            name: 'invalid characters in attributes',
            input: '@div[key=val <] something',
            error: /Lexer error/
        },
        {
            name: 'malformed special attributes',
            input: '@div.#idName',
            error: /Lexer error/
        },
        {
            name: 'missing attribute value',
            input: '@div[key=] ok',
            error: /Lexer error/
        }
    ]

    bad_examples.forEach(function(example) {
        it('fails when ' + example.name, function() {
            assert.throws(function() {
                omeletToHtml(example.input)
            }, example.error)
        })
    })
})

describe('Filters', function() {
    const context = {
        word: 'omelet',
        sentence: 'Omelet is cool!',
        padded: '     lots of spaces        ',
        number: 47,
        listOfNumbers: [4, 8, 15, 16, 23, 42],
        listUnsorted: [42, 8, 16, 4, 23, 15],
        listOfMixed: [true, 47, 'hello', 23, 42, 23],
        listShort: ['lol'],
        listOfObjects: [
            {
                name: 'book',
                price: 20,
                date: new Date('12/23/1993')
            },
            {
                name: 'sandwich',
                price: 7,
                date: new Date('5/15/2016')
            },
            {
                name: 'coffee',
                price: 2,
                date: new Date('10/20/2014')
            }
        ],
        listOfLists: [
            [1, 2, 3],
            [4, 5, 6],
            [7, 8, 9]
        ],
        object: {
            price: 20,
            name: 'book',
            date: new Date('12/23/1993')
        },
        cat: {
            age: 7
        },
        date1: new Date('12/23/1993'),
        date2: new Date('5/15/2016'),
        dateWithTime: new Date('Thu, 23 Dec 1993 17:43:00 GMT'),
        multiDate: {
            sunday: new Date('5/15/2016'),
            monday: new Date('8/15/1994'),
            tuesday: new Date('9/4/2007'),
            wednesday: new Date('11/4/1964'),
            thursday: new Date('12/23/1993'),
            friday: new Date('7/18/1986'),
            saturday: new Date('1/10/1920')
        },
        dateString: '12/23/1993',
        dateStringList: ['2/1/2016', 'March 3, 2016', '4 April 2016', 'Jun 5 2016', 'October 31 2016'],
        htmlString: '<h1 id="anchor">hello, world!</h1>',
        unsafeString1: '<script>console.log("gotcha");</script>',
        unsafeString2: 'x & y',
        emptyString: '',
        nullValue: null,
        undefinedValue: undefined
    }

    const options = {}

    const examples = [
        {<commit_msg>Fixed test failure due to time zone<commit_after>const assert = require('assert')
const lexer = require('../lib/lexer.js')
const parser = require('../lib/parser.js')
const linker = require('../lib/linker.js')
const compiler = require('../lib/compiler.js')
const util = require('../lib/util.js')
const runtime = require('../lib/runtime.js')
const omelet = require('../lib/omelet.js')

function omeletToHtml(input, context, options) {
    context = context || {}
    options = options || {}
    const tokens = lexer.lex(input, options),
        ast = parser.parse(tokens, options),
        linkedAst = linker.link(ast, options),
        template = compiler.compile(linkedAst, options)
    return template(context)
}

describe('Tags', function() {
    const context = {}
    const options = {}

    const examples = [
        {
            name: 'plain tag',
            input: '@h1 hello, world!',
            output: '<h1>hello, world!</h1>'
        },
        {
            name: 'several tags',
            input: '@h1 hello, world!\n@h2 hi!\n@h3 this is omelet',
            output: '<h1>hello, world!</h1>\n<h2>hi!</h2>\n<h3>this is omelet</h3>'
        },
        {
            name: 'tags with attributes',
            input: '@a#anchor.className[href="#" target="_blank"] click me',
            output: '<a class="className" id="anchor" href="#" target="_blank">click me</a>'
        },
        {
            name: 'tags with multiple class attributes',
            input: '@h1.classOne#idName.classTwo hello, world!',
            output: '<h1 class="classOne classTwo" id="idName">hello, world!</h1>'
        },
        {
            name: 'tags with boolean attributes',
            input: '@input[type=checkbox checked]',
            output: '<input type="checkbox" checked="checked"/>'
        },
        {
            name: 'multitags',
            input: '@b|i.classy|u testing',
            output: '<b><i class="classy"><u>testing</u></i></b>'
        },
        {
            name: 'nested block tags',
            input: '@div\n  @div\n    @h1 hello!\n  @div\n    @h2 hello!',
            output: '<div>\n    <div>\n        <h1>hello!</h1>\n    </div>\n    <div>\n        <h2>hello!</h2>\n    </div>\n</div>'
        }
    ]

    examples.forEach(function(example) {
        it('translates ' + example.name, function() {
            assert.equal(omeletToHtml(example.input, context, options), example.output)
        })
    })

    const bad_examples = [
        {
            name: 'invalid characters in attributes',
            input: '@div[key=val <] something',
            error: /Lexer error/
        },
        {
            name: 'malformed special attributes',
            input: '@div.#idName',
            error: /Lexer error/
        },
        {
            name: 'missing attribute value',
            input: '@div[key=] ok',
            error: /Lexer error/
        }
    ]

    bad_examples.forEach(function(example) {
        it('fails when ' + example.name, function() {
            assert.throws(function() {
                omeletToHtml(example.input)
            }, example.error)
        })
    })
})

describe('Filters', function() {
    const context = {
        word: 'omelet',
        sentence: 'Omelet is cool!',
        padded: '     lots of spaces        ',
        number: 47,
        listOfNumbers: [4, 8, 15, 16, 23, 42],
        listUnsorted: [42, 8, 16, 4, 23, 15],
        listOfMixed: [true, 47, 'hello', 23, 42, 23],
        listShort: ['lol'],
        listOfObjects: [
            {
                name: 'book',
                price: 20,
                date: new Date('12/23/1993')
            },
            {
                name: 'sandwich',
                price: 7,
                date: new Date('5/15/2016')
            },
            {
                name: 'coffee',
                price: 2,
                date: new Date('10/20/2014')
            }
        ],
        listOfLists: [
            [1, 2, 3],
            [4, 5, 6],
            [7, 8, 9]
        ],
        object: {
            price: 20,
            name: 'book',
            date: new Date('12/23/1993')
        },
        cat: {
            age: 7
        },
        date1: new Date('12/23/1993'),
        date2: new Date('5/15/2016'),
        dateWithTime: new Date('Thu, 23 Dec 1993 9:43:00'),
        multiDate: {
            sunday: new Date('5/15/2016'),
            monday: new Date('8/15/1994'),
            tuesday: new Date('9/4/2007'),
            wednesday: new Date('11/4/1964'),
            thursday: new Date('12/23/1993'),
            friday: new Date('7/18/1986'),
            saturday: new Date('1/10/1920')
        },
        dateString: '12/23/1993',
        dateStringList: ['2/1/2016', 'March 3, 2016', '4 April 2016', 'Jun 5 2016', 'October 31 2016'],
        htmlString: '<h1 id="anchor">hello, world!</h1>',
        unsafeString1: '<script>console.log("gotcha");</script>',
        unsafeString2: 'x & y',
        emptyString: '',
        nullValue: null,
        undefinedValue: undefined
    }

    const options = {}

    const examples = [
        {
{'fraction_non_alphanumeric': 0.16139457447850358, 'fraction_numerical': 0.04201351483694055, 'mean_word_length': 1.6157786885245902, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 69, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1943401', 'n_tokens_mistral': 3424, 'n_tokens_neox': 3065, 'n_words': 711}