Last active
November 12, 2017 13:26
-
-
Save erukiti/2222af751458e443d395bf1199f3a46b to your computer and use it in GitHub Desktop.
s2s-handler-pegjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//@flow | |
import peg from 'pegjs' | |
import type { Code } from 'types' | |
export default function pegjsHandler(code: Code): Code { | |
if (code === '') { | |
return '' | |
} | |
return peg.generate(code, { output: 'source', format: 'commonjs' }) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//@flow | |
import fs from 'fs' | |
import os from 'os' | |
import path from 'path' | |
import handler from '.' | |
const code = 'start = [a-z]+ {return text()}' | |
test('hndlerは返還後のコードを返す', () => { | |
const result = handler(code) | |
const dir = fs.mkdtempSync(`${os.tmpdir()}${path.sep}`) | |
const filename = `${dir}/index.js` | |
fs.writeFileSync(filename, result) | |
// FIXME: Flowの警告が消せない… | |
// eslint-disable-next-line global-require, import/no-dynamic-require | |
const parser = require(dir) | |
expect(parser.parse('hoge')).toBe('hoge') | |
}) | |
test('codeが""の場合、""が返ること', () => { | |
const result = handler('') | |
expect(result).toBe('') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment