<commit_before>import { expect } from 'chai'
import Up from '../../../index'
import { Link } from '../../../SyntaxNodes/Link'
import { PlainText } from '../../../SyntaxNodes/PlainText'
import { Emphasis } from '../../../SyntaxNodes/Emphasis'
import { Footnote } from '../../../SyntaxNodes/Footnote'
import { UpDocument } from '../../../SyntaxNodes/UpDocument'
import { Paragraph } from '../../../SyntaxNodes/Paragraph'
import { Heading } from '../../../SyntaxNodes/Heading'


context('Inside a link', () => {
  specify("a footnote does not produce another <a> element. The footnote's <sup> directly contains the footnote's reference number", () => {
    const document = new UpDocument([
      new Paragraph([
        new Link([
          new PlainText('Google'),
          new Footnote([new PlainText('A really old search engine.')], { referenceNumber: 2 })
        ], 'https://google.com')
      ])
    ])

    expect(Up.toHtml(document)).to.be.eql(
      '<p><a href="https://google.com">Google<sup class="up-footnote-reference" id="up-footnote-reference-2">2</sup></a></p>')
  })

  specify("a nested link does not produce another <a> element. The nested link's contents are included directly inside the outer link", () => {
    const document = new UpDocument([
      new Paragraph([
        new Link([
          new PlainText('Google is probably not '),
          new Link([new PlainText('Bing')], 'https://bing.com')
        ], 'https://google.com')
      ])
    ])

    expect(Up.toHtml(document)).to.be.eql('<p><a href="https://google.com">Google is probably not Bing</a></p>')
  })
})


describe('A link nested within a table of contents entries', () => {
  it('does not produce an <a> element', () => {
    const heading =
      new Heading([
        new Link([new PlainText('I enjoy apples')], 'https://google.com')
      ], { level: 1, ordinalInTableOfContents: 1 })

    const document =
      new UpDocument([heading], new UpDocument.TableOfContents([heading]))

    expect(Up.toHtml(document)).to.be.eql(
      '<nav class="up-table-of-contents">'
      + '<h1>Table of Contents</h1>'
      + '<ul>'
      + '<li><h2><a href="#up-item-1">I enjoy apples</a></h2></li>'
      + '</ul>'
      + '</nav>'
      + '<h1 id="up-item-1"><a href="https://google.com">I enjoy apples</a></h1>')
  })
})


context("Even when a link is nested deep within another link, it doesn't produce an <a> element. This is true for", () => {
  specify("a link inside another link", () => {
    const document = new UpDocument([
      new Paragraph([
        new Link([
          new Emphasis([
            new PlainText('Google'),
            new Footnote([new PlainText('A really old search engine.')], { referenceNumber: 2 })
          ])
        ], 'https://google.com')
      ])
    ])

    expect(Up.toHtml(document)).to.be.eql(
      '<p>'
      + '<a href="https://google.com"><em>Google<sup class="up-footnote-reference" id="up-footnote-reference-2">2</sup></em></a>'
      + '</p>')
  })

  specify("a footnote inside a link", () => {
    const document = new UpDocument([
      new Paragraph([
        new Link([
          new Emphasis([
            new PlainText('Google is probably not '),
            new Link([new PlainText('Bing')], 'https://bing.com')
          ])
        ], 'https://google.com')
      ])
    ])

    expect(Up.toHtml(document)).to.be.eql(
      '<p>'
      + '<a href="https://google.com"><em>Google is probably not Bing</em></a>'
      + '</p>')
  })

  specify('a link nested within another link within a table of contents entry', () => {
    const heading =
      new Heading([
        new Link([
          new Emphasis([
            new Link([new PlainText('I enjoy apples')], 'https://bing.com')
          ])
        ], 'https://apple.com')
      ], { level: 1, ordinalInTableOfContents: 1 })

    const document =
      new UpDocument([heading], new UpDocument.TableOfContents([heading]))<commit_msg>Fix test descriptions<commit_after>import { expect } from 'chai'
import Up from '../../../index'
import { Link } from '../../../SyntaxNodes/Link'
import { PlainText } from '../../../SyntaxNodes/PlainText'
import { Emphasis } from '../../../SyntaxNodes/Emphasis'
import { Footnote } from '../../../SyntaxNodes/Footnote'
import { UpDocument } from '../../../SyntaxNodes/UpDocument'
import { Paragraph } from '../../../SyntaxNodes/Paragraph'
import { Heading } from '../../../SyntaxNodes/Heading'


context('Inside a link', () => {
  specify("a footnote does not produce another <a> element. The footnote's <sup> directly contains the footnote's reference number", () => {
    const document = new UpDocument([
      new Paragraph([
        new Link([
          new PlainText('Google'),
          new Footnote([new PlainText('A really old search engine.')], { referenceNumber: 2 })
        ], 'https://google.com')
      ])
    ])

    expect(Up.toHtml(document)).to.be.eql(
      '<p><a href="https://google.com">Google<sup class="up-footnote-reference" id="up-footnote-reference-2">2</sup></a></p>')
  })

  specify("a nested link does not produce another <a> element. The nested link's contents are included directly inside the outer link", () => {
    const document = new UpDocument([
      new Paragraph([
        new Link([
          new PlainText('Google is probably not '),
          new Link([new PlainText('Bing')], 'https://bing.com')
        ], 'https://google.com')
      ])
    ])

    expect(Up.toHtml(document)).to.be.eql('<p><a href="https://google.com">Google is probably not Bing</a></p>')
  })
})


describe('A link nested within a table of contents entry', () => {
  it('does not produce an <a> element', () => {
    const heading =
      new Heading([
        new Link([new PlainText('I enjoy apples')], 'https://google.com')
      ], { level: 1, ordinalInTableOfContents: 1 })

    const document =
      new UpDocument([heading], new UpDocument.TableOfContents([heading]))

    expect(Up.toHtml(document)).to.be.eql(
      '<nav class="up-table-of-contents">'
      + '<h1>Table of Contents</h1>'
      + '<ul>'
      + '<li><h2><a href="#up-item-1">I enjoy apples</a></h2></li>'
      + '</ul>'
      + '</nav>'
      + '<h1 id="up-item-1"><a href="https://google.com">I enjoy apples</a></h1>')
  })
})


context("When a link is nested deeply within another link, it doesn't produce an <a> element. This is true for:", () => {
  specify("A footnote nested deeply within a link", () => {
    const document = new UpDocument([
      new Paragraph([
        new Link([
          new Emphasis([
            new PlainText('Google'),
            new Footnote([new PlainText('A really old search engine.')], { referenceNumber: 2 })
          ])
        ], 'https://google.com')
      ])
    ])

    expect(Up.toHtml(document)).to.be.eql(
      '<p>'
      + '<a href="https://google.com"><em>Google<sup class="up-footnote-reference" id="up-footnote-reference-2">2</sup></em></a>'
      + '</p>')
  })

  specify("A link nested deeply within another a link", () => {
    const document = new UpDocument([
      new Paragraph([
        new Link([
          new Emphasis([
            new PlainText('Google is probably not '),
            new Link([new PlainText('Bing')], 'https://bing.com')
          ])
        ], 'https://google.com')
      ])
    ])

    expect(Up.toHtml(document)).to.be.eql(
      '<p>'
      + '<a href="https://google.com"><em>Google is probably not Bing</em></a>'
      + '</p>')
  })

  specify('a link nested within another link within a table of contents entry', () => {
    const heading =
      new Heading([
        new Link([
          new Emphasis([
            new Link([new PlainText('I enjoy apples')], 'https://bing.com')
          ])
        ], 'https://apple.com')
      ], { level: 1, ordinalInTableOfContents: 1 })

    const document =
      new UpDocument([heading], new UpDocument.TableOfContents([heading]))
{'fraction_non_alphanumeric': 0.1889873417721519, 'fraction_numerical': 0.004556962025316456, 'mean_word_length': 2.5638249887235003, 'pattern_counts': {'":': 0, '<': 93, '<?xml version=': 0, '>': 111, 'https://': 28, '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': '7370838', 'n_tokens_mistral': 2413, 'n_tokens_neox': 2338, 'n_words': 611}