Skip to content

Commit

Permalink
Remove duplicated tests in gatsby-remark-prismjs (#1965)
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentbel authored and KyleAMathews committed Aug 30, 2017
1 parent bd2b5e6 commit 12d2ae8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 69 deletions.
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`)
})
})

0 comments on commit 12d2ae8

Please sign in to comment.