Skip to content

Commit

Permalink
Update tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
denysdovhan committed Nov 27, 2015
1 parent 76896ae commit f5d14a5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 59 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
"mdast": "^2.1.0",
"mocha": "*",
"npm-run-all": "*",
"rimraf": "*"
"rimraf": "*",
"typographic-base": "^1.0.1"
},
"dependencies": {
"textr": "^0.3.0",
Expand Down
72 changes: 14 additions & 58 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,77 +1,33 @@
import { equal } from 'assert';
import mdast from 'mdast';
import typographer from './';
import base from 'typographic-base';
import typographer from './index';

const t = (text, options) =>
mdast().use(typographer, options).process(text).trim();

describe('mdast-typographer', () => {
describe('mdast-textr', () => {

it('should transform', () => {
equal(t(`rock'n'rol`), `rock’n’rol`, 'apostrophes');
equal(t(`sisters' friends'`), `sisters’ friends’`, 'plurals');
equal(t(`-> <-`), `→ ←`, 'arrows');
equal(t(`(c)`), `©`, 'copyright');
equal(t(`1USD = 23,7UAH`), `1$ = 23,7₴`, 'currency');
equal(t(`... ... ...`), `… … …`, 'currency');
equal(t(`foo -- bar`), `foo — bar`, 'em-dashes');
equal(t(`(1967-1994)`), `(1967–1994)`, 'en-dashes');
equal(t(`10 -+ 1`), `10 ∓ 1`, 'math');
equal(t(`"quotes"`), `“quotes”`, 'quotes');
equal(t(`(R)`), `®`, 'registered');
equal(t(`foo bar`), `foo bar`, 'spaces');
equal(t(`(TM)`), `™`, 'trademark');
});

it('should remove disabled transformers', () =>
equal(
t(`Ellipses... and "quotes"`, {
modules: {
ellipses: false
}
}),
`Ellipses... and “quotes”`
)
);

it('should remove all transformers', () =>
equal(
t(`Ellipses... and "quotes"`, {
modules: false
}),
`Ellipses... and "quotes"`
)
);

it('should load locale', () =>
equal(t(`"quotes"`, { locale: 'uk' }), `«quotes»`)
);

it('should use after transformers', () =>
equal(
t(`Hello, "world".`, {
after: [(t) => t.replace('world', 'guys')]
}),
`Hello, “guys”.`
)
it('should return original text', () =>
equal(t(`Hello, "world"...`), `Hello, "world"...`)
);

it('should use before transformers', () =>
it('should return transformed text', () =>
equal(
t(`Hello, "world"!`, {
before: [(t) => t.replace(/"/g, '')]
t(`Hello, "world"...`, {
plugins: [ base ]
}),
`Hello, world!`
`Hello, world”…`
)
);

it('should use after and before transformers', () =>
it('should load options', () =>
equal(
t(`Hello, "world"!`, {
before: [(t) => t.replace(/"/g, '')],
after: [(t) => t.replace('world', 'guys')]
t(`"quotes"`, {
locale: 'uk',
plugins: [ base ]
}),
`Hello, guys!`
`«quotes»`
)
);

Expand Down

0 comments on commit f5d14a5

Please sign in to comment.