<commit_before>import { expect } from 'chai'
import Up from '../../../index'
import { DocumentNode } from '../../../SyntaxNodes/DocumentNode'
import { CodeBlockNode } from '../../../SyntaxNodes/CodeBlockNode'
import { ParagraphNode } from '../../../SyntaxNodes/ParagraphNode'
import { LineBlockNode } from '../../../SyntaxNodes/LineBlockNode'
import { Line } from '../../../SyntaxNodes/Line'
import { PlainTextNode } from '../../../SyntaxNodes/PlainTextNode'




describe('A code block', () => {
  it('can directly follow a paragraph', () => {
    const text = `
My pies never turn out quite right.
\`\`\`
const pie = 3.5
\`\`\``

    expect(Up.toAst(text)).to.be.eql(
      new DocumentNode([
        new ParagraphNode([
          new PlainTextNode('My pies never turn out quite right.')
        ]),
        new CodeBlockNode('const pie = 3.5')
      ]))
  })

  it('can directly follow a line block', () => {
    const text = `
Roses are red
Violets are white
My pies just never
Turn out quite right
\`\`\`
const pie = 3.5
\`\`\``

    expect(Up.toAst(text)).to.be.eql(
      new DocumentNode([
        new LineBlockNode([
          new Line([
            new PlainTextNode('Roses are red')
          ]),
          new Line([
            new PlainTextNode('Violets are white')
          ]),
          new Line([
            new PlainTextNode('My pies just never')
          ]),
          new Line([
            new PlainTextNode('Turn out quite right')
          ])
        ]),
        new CodeBlockNode('const pie = 3.5')
      ]))
  })

  it('can be directly followed by a paragraph', () => {
    const text = `
\`\`\`
const pie = 3.5
\`\`\`
My pies never turn out quite right.`

    expect(Up.toAst(text)).to.be.eql(
      new DocumentNode([
        new CodeBlockNode('const pie = 3.5'),
        new ParagraphNode([
          new PlainTextNode('My pies never turn out quite right.')
        ])
      ]))
  })
})


describe('A code block with containing zero lines of code', () => {
  it('produces an empty code block', () => {
    const text = `
\`\`\`
\`\`\``
    expect(Up.toAst(text)).to.be.eql(
      new DocumentNode([
        new CodeBlockNode(''),
      ]))
  })
})


describe('An unmatched streak of backticks, following a normal "enclosed" code block whose streaks are the same length as the unmatched streak,', () => {
  it("produces a code block node containing the rest of the document", () => {
    const text = `
Check out the code below!

\`\`\`
function factorial(n: number): number {
  return (
    n <= 1
      ? 1
      : n * factorial(n - 1))
}
\`\`\`
<commit_msg>Add passing code block test<commit_after>import { expect } from 'chai'
import Up from '../../../index'
import { DocumentNode } from '../../../SyntaxNodes/DocumentNode'
import { CodeBlockNode } from '../../../SyntaxNodes/CodeBlockNode'
import { ParagraphNode } from '../../../SyntaxNodes/ParagraphNode'
import { LineBlockNode } from '../../../SyntaxNodes/LineBlockNode'
import { Line } from '../../../SyntaxNodes/Line'
import { PlainTextNode } from '../../../SyntaxNodes/PlainTextNode'




describe('A code block', () => {
  it('can directly follow a paragraph', () => {
    const text = `
My pies never turn out quite right.
\`\`\`
const pie = 3.5
\`\`\``

    expect(Up.toAst(text)).to.be.eql(
      new DocumentNode([
        new ParagraphNode([
          new PlainTextNode('My pies never turn out quite right.')
        ]),
        new CodeBlockNode('const pie = 3.5')
      ]))
  })

  it('can directly follow a line block', () => {
    const text = `
Roses are red
Violets are white
My pies just never
Turn out quite right
\`\`\`
const pie = 3.5
\`\`\``

    expect(Up.toAst(text)).to.be.eql(
      new DocumentNode([
        new LineBlockNode([
          new Line([
            new PlainTextNode('Roses are red')
          ]),
          new Line([
            new PlainTextNode('Violets are white')
          ]),
          new Line([
            new PlainTextNode('My pies just never')
          ]),
          new Line([
            new PlainTextNode('Turn out quite right')
          ])
        ]),
        new CodeBlockNode('const pie = 3.5')
      ]))
  })

  it('can be directly followed by a paragraph', () => {
    const text = `
\`\`\`
const pie = 3.5
\`\`\`
My pies never turn out quite right.`

    expect(Up.toAst(text)).to.be.eql(
      new DocumentNode([
        new CodeBlockNode('const pie = 3.5'),
        new ParagraphNode([
          new PlainTextNode('My pies never turn out quite right.')
        ])
      ]))
  })
})


context('A code block with containing zero lines of code produces an empty code block', () => {
  specify('when it has a closing streak', () => {
    const text = `
\`\`\`
\`\`\``
    expect(Up.toAst(text)).to.be.eql(
      new DocumentNode([
        new CodeBlockNode(''),
      ]))
  })

  specify('when it lacks a closing streak', () => {
    expect(Up.toAst('```')).to.be.eql(
      new DocumentNode([
        new CodeBlockNode(''),
      ]))
  })
})


describe('An unmatched streak of backticks, following a normal "enclosed" code block whose streaks are the same length as the unmatched streak,', () => {
  it("produces a code block node containing the rest of the document", () => {
    const text = `
Check out the code below!

\`\`\`
function factorial(n: number): number {
  return (
    n <= 1
      ? 1
      : n * factorial(n - 1))
}
\`\`\`

{'fraction_non_alphanumeric': 0.1653674832962138, 'fraction_numerical': 0.005567928730512249, 'mean_word_length': 2.19632265717675, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 20, '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': '1540237', 'n_tokens_mistral': 1742, 'n_tokens_neox': 1670, 'n_words': 493}