Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove duplicated tests in gatsby-remark-prismjs #1965

Merged
merged 2 commits into from
Aug 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`highlight code and lines with PrismJS highlights code for language cpp 1`] = `
exports[`highlight code and lines with PrismJS for language cpp 1`] = `
"<span class=\\"gatsby-highlight-code-line\\">
</span><span class=\\"gatsby-highlight-code-line\\"><span class=\\"token keyword\\">int</span> <span class=\\"token function\\">sum</span><span class=\\"token punctuation\\">(</span>a<span class=\\"token punctuation\\">,</span> b<span class=\\"token punctuation\\">)</span> <span class=\\"token punctuation\\">{</span>
</span> <span class=\\"token keyword\\">return</span> a <span class=\\"token operator\\">+</span> b<span class=\\"token punctuation\\">;</span>
Expand All @@ -9,7 +9,7 @@ exports[`highlight code and lines with PrismJS highlights code for language cpp
"
`;

exports[`highlight code and lines with PrismJS highlights code for language jsx 1`] = `
exports[`highlight code and lines with PrismJS for language jsx 1`] = `
"
<span class=\\"token keyword\\">import</span> React <span class=\\"token keyword\\">from</span> <span class=\\"token string\\">\\"react\\"</span>

Expand Down
86 changes: 19 additions & 67 deletions packages/gatsby-remark-prismjs/src/__tests__/highlight-code.js
Original file line number Diff line number Diff line change
@@ -1,74 +1,27 @@
const parseLineNumberRange = require(`../parse-line-number-range`)

describe(`highlight code and lines with PrismJS`, () => {
it(`parses numeric ranges from the languages variable`, () => {
expect(parseLineNumberRange(`jsx{1,5,7-8}`).highlightLines).toEqual([
1,
5,
7,
8,
])
expect(parseLineNumberRange(`javascript{7-8}`).highlightLines).toEqual([
7,
8,
])
expect(parseLineNumberRange(`javascript{7..8}`).highlightLines).toEqual([
7,
8,
])
expect(parseLineNumberRange(`javascript{2}`).highlightLines).toEqual([2])
expect(parseLineNumberRange(`javascript{2,4-5}`).highlightLines).toEqual([
2,
4,
5,
])
})
it(`ignores negative numbers`, () => {
expect(parseLineNumberRange(`jsx{-1,1,5,7-8}`).highlightLines).toEqual([
1,
5,
7,
8,
])
expect(parseLineNumberRange(`jsx{-1..4}`).highlightLines).toEqual([
1,
2,
3,
4,
])
})
it(`handles bad inputs`, () => {
expect(parseLineNumberRange(`jsx{-1`).highlightLines).toEqual([])
expect(parseLineNumberRange(`jsx{-1....`).highlightLines).toEqual([])
afterEach(() => {
jest.resetModules()
})
it(`parses languages without ranges`, () => {
expect(parseLineNumberRange(`jsx`).splitLanguage).toEqual(`jsx`)
})

describe(`highlights code for language`, () => {
afterEach(() => {
jest.resetModules()
})

it(`cpp`, () => {
const highlightCode = require(`../highlight-code`)
const language = `cpp`
const lineNumbersHighlight = [1, 2]
const code = `
it(`for language cpp`, () => {
const highlightCode = require(`../highlight-code`)
const language = `cpp`
const lineNumbersHighlight = [1, 2]
const code = `
int sum(a, b) {
return a + b;
}
`
expect(
highlightCode(language, code, lineNumbersHighlight)
).toMatchSnapshot()
})
expect(
highlightCode(language, code, lineNumbersHighlight)
).toMatchSnapshot()
})

it(`jsx`, () => {
const highlightCode = require(`../highlight-code`)
const language = `jsx`
const lineNumbersHighlight = [12, 13, 15]
const code = `
it(`for language jsx`, () => {
const highlightCode = require(`../highlight-code`)
const language = `jsx`
const lineNumbersHighlight = [12, 13, 15]
const code = `
import React from "react"

class Counter extends React.Component {
Expand All @@ -95,9 +48,8 @@ class Counter extends React.Component {

export default Counter
`
expect(
highlightCode(language, code, lineNumbersHighlight)
).toMatchSnapshot()
})
expect(
highlightCode(language, code, lineNumbersHighlight)
).toMatchSnapshot()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe(`parses numeric ranges from the languages markdown code directive`, ()
5,
])
})

it(`ignores negative numbers`, () => {
expect(parseLineNumberRange(`jsx{-1,1,5,7-8}`).highlightLines).toEqual([
1,
Expand All @@ -37,8 +38,13 @@ describe(`parses numeric ranges from the languages markdown code directive`, ()
4,
])
})

it(`handles bad inputs`, () => {
expect(parseLineNumberRange(`jsx{-1`).highlightLines).toEqual([])
expect(parseLineNumberRange(`jsx{-1....`).highlightLines).toEqual([])
})

it(`parses languages without ranges`, () => {
expect(parseLineNumberRange(`jsx`).splitLanguage).toEqual(`jsx`)
})
})