<commit_before>assert = require 'power-assert'
bHtml = require './'

describe 'NewLineText (|)', ->
  it 'works', ->
    source = '''
      |text
    '''
    assert bHtml(source) is '\ntext'
    assert bHtml(source, format: 'demo') is '''
      text
    '''

    source = '''
      |line1
      |line2
    '''
    assert bHtml(source) is '\nline1\nline2'
    assert bHtml(source, format: 'demo') is '''
      line1
      line2
    '''

    source = '''
      <p
        |text
    '''
    assert bHtml(source) is '<p>\ntext</p>'
    assert bHtml(source, format: 'demo') is '''
      <p>
        text
      </p>
    '''

    source = '''
      <p
        |line1
        |line2
    '''
    assert bHtml(source) is '<p>\nline1\nline2</p>'
    assert bHtml(source, format: 'demo') is '''
      <p>
        line1
        line2
      </p>
    '''

    source = '''
      <p
        |line1
        |
        |line3
    '''
    assert bHtml(source) is '<p>\nline1\n\nline3</p>'
    # NOTE: prevent to remove trailing spaces
    assert bHtml(source, format: 'demo') is '<p>\n  line1\n  \n  line3\n</p>'

    # NOTE: escape attribute
    source = '''
      |@text
    '''
    assert bHtml(source) is '\n@text'
    assert bHtml(source, format: 'demo') is '''
      @text
    '''

    # NOTE: escape element
    source = '''
      |<text
    '''
    assert bHtml(source) is '\n<text'
    assert bHtml(source, format: 'demo') is '''
      <text
    '''

    # NOTE: escape text
    source = '''
      |>text
    '''
    assert bHtml(source) is '\n>text'
    assert bHtml(source, format: 'demo') is '''
      >text
    '''

  context '(errors)', ->
    it 'works', ->
      f = ->
        bHtml '''
          |line1
              |line2
        '''
      assert.throws f, ({ columnNumber, lineNumber, message }) ->
        assert columnNumber is 5
        assert lineNumber is 2
        assert message is 'too deep indentation'
        true

      f = ->
        bHtml '''
          |line1
            |line2
        '''
      assert.throws f, ({ columnNumber, lineNumber, message }) ->
        assert columnNumber is 3
        assert lineNumber is 2
        assert message is 'new line text must not have a child'
        true<commit_msg>add tests for new line text with format option<commit_after>assert = require 'power-assert'
bHtml = require './'

describe 'NewLineText (|)', ->
  context '1', ->
    it 'works', ->
      source = '''
        |text
      '''
      format = (nodes, options) ->
        assert nodes.length is 1
        assert nodes[0].type is 'new line text'
        assert nodes[0].value is 'text'
        assert.deepEqual options, { format }
      bHtml source, { format }
      assert bHtml(source) is '\ntext'
      assert bHtml(source, format: 'demo') is '''
        text
      '''

  context '2', ->
    it 'works', ->
      source = '''
        |line1
        |line2
      '''
      format = (nodes, options) ->
        assert nodes.length is 2
        assert nodes[0].type is 'new line text'
        assert nodes[0].value is 'line1'
        assert nodes[1].type is 'new line text'
        assert nodes[1].value is 'line2'
        assert.deepEqual options, { format }
      bHtml source, { format }
      assert bHtml(source) is '\nline1\nline2'
      assert bHtml(source, format: 'demo') is '''
        line1
        line2
      '''

  context '3', ->
    it 'works', ->
      source = '''
        <p
          |text
      '''
      format = (nodes, options) ->
        assert nodes.length is 1
        assert nodes[0].type is 'element'
        assert nodes[0].name is 'p'
        assert nodes[0].attributes.length is 0
        assert nodes[0].children.length is 1
        assert nodes[0].children[0].type is 'new line text'
        assert nodes[0].children[0].value is 'text'
        assert.deepEqual options, { format }
      bHtml source, { format }
      assert bHtml(source) is '<p>\ntext</p>'
      assert bHtml(source, format: 'demo') is '''
        <p>
          text
        </p>
      '''

  context '4', ->
    it 'works', ->
      source = '''
        <p
          |line1
          |line2
      '''
      format = (nodes, options) ->
        assert nodes.length is 1
        assert nodes[0].type is 'element'
        assert nodes[0].name is 'p'
        assert nodes[0].attributes.length is 0
        assert nodes[0].children.length is 2
        assert nodes[0].children[0].type is 'new line text'
        assert nodes[0].children[0].value is 'line1'
        assert nodes[0].children[1].type is 'new line text'
        assert nodes[0].children[1].value is 'line2'
        assert.deepEqual options, { format }
      bHtml source, { format }
      assert bHtml(source) is '<p>\nline1\nline2</p>'
      assert bHtml(source, format: 'demo') is '''
        <p>
          line1
          line2
        </p>
      '''

  context '5', ->
    it 'works', ->
      source = '''
        <p
          |line1
          |
          |line3
      '''
      format = (nodes, options) ->
        assert nodes.length is 1
        assert nodes[0].type is 'element'
        assert nodes[0].name is 'p'
        assert nodes[0].attributes.length is 0
        assert nodes[0].children.length is 3
        assert nodes[0].children[0].type is 'new line text'
        assert nodes[0].children[0].value is 'line1'
        assert nodes[0].children[1].type is 'new line text'
        assert nodes[0].children[1].value is ''
        assert nodes[0].children[2].type is 'new line text'
        assert nodes[0].children[2].value is 'line3'
        assert.deepEqual options, { format }
      bHtml source, { format }
      assert bHtml(source) is '<p>\nline1\n\nline3</p>'
      # NOTE: prevent to remove trailing spaces
      assert bHtml(source, format: 'demo') is '<p>\n  line1\n  \n  line3\n</p>'

  context '6', ->
    it 'works', ->
      # NOTE: escape attribute
      source = '''
        |@text
      '''
      format = (nodes, options) ->
        assert nodes.length is 1
        assert nodes[0].type is 'new line text'
        assert nodes[0].value is '@text'
        assert.deepEqual options, { format }
      bHtml source, { format }
      assert bHtml(source) is '\n@text'
      assert bHtml(source, format: 'demo') is '''
        @text
      '''

  context '7', ->
    it 'works', ->
      # NOTE: escape element
      source = '''
        |<text
      '''
      format = (nodes, options) ->
        assert nodes.length is 1
        assert nodes[0].type is 'new line text'
        assert nodes[0].value is '<text'
        assert.deepEqual options, { format }
      bHtml source, { format }
      assert bHtml(source) is '\n<text'
      assert bHtml(source, format: 'demo') is '''
        <text
      '''

  context '8', ->
    it 'works', ->
      # NOTE: escape text
      source = '''
        |>text
      '''
      format = (nodes, options) ->
        assert nodes.length is 1
        assert nodes[0].type is 'new line text'
        assert nodes[0].value is '>text'
        assert.deepEqual options, { format }
      bHtml source, { format }
      assert bHtml(source) is '\n>text'
      assert bHtml(source, format: 'demo') is '''
        >text
      '''

  context '(errors)', ->
    it 'works', ->
      f = ->
        bHtml '''
          |line1
              |line2
        '''
      assert.throws f, ({ columnNumber, lineNumber, message }) ->
        assert columnNumber is 5
        assert lineNumber is 2
        assert message is 'too deep indentation'
        true

      f = ->
        bHtml '''
          |line1
            |line2
        '''
      assert.throws f, ({ columnNumber, lineNumber, message }) ->
        assert columnNumber is 3
        assert lineNumber is 2
        assert message is 'new line text must not have a child'
        true
{'fraction_non_alphanumeric': 0.13927146350881708, 'fraction_numerical': 0.01647573690307633, 'mean_word_length': 1.736879182810849, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 73, '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': '4203827', 'n_tokens_mistral': 2387, 'n_tokens_neox': 2340, 'n_words': 692}