<commit_before>expect        = require 'expect.js'
_             = require 'underscore'
utils         = require '../lib/utils'

describe "utils", ->

  it "encodes CSV", ->
    expect(utils.array_to_csv([
      ["this", "that", 'quoted "things"', '"Yo", ze said'],
      ["wut", "ok", "yah", 0, undefined, null, "a\nb"]
    ])).to.be('''this,that,quoted ""things"","""Yo"", ze said"\nwut,ok,yah,0,,,"a\nb"''')

  it "absolutizes urls", ->
    expect(
      utils.absolutize_url("http://example.com", "/this/that")
    ).to.be("http://example.com/this/that")
    expect(
      utils.absolutize_url("http://example.com", "http://example2.com/this/that")
    ).to.be("http://example2.com/this/that")
    expect(
      utils.absolutize_url("https://example.com", "/this/that")
    ).to.be("https://example.com/this/that")

  it "Checks equality of sharing settings: empty lists", ->
    future = new Date()
    expect(utils.sharing_is_equal({
      public_view_until: future<commit_msg>Add test for previous crash bug<commit_after>expect        = require 'expect.js'
_             = require 'underscore'
utils         = require '../lib/utils'

describe "utils", ->

  it "encodes CSV", ->
    expect(utils.array_to_csv([
      ["this", "that", 'quoted "things"', '"Yo", ze said'],
      ["wut", "ok", "yah", 0, undefined, null, "a\nb"]
    ])).to.be('''this,that,quoted ""things"","""Yo"", ze said"\nwut,ok,yah,0,,,"a\nb"''')

  it "absolutizes urls", ->
    expect(
      utils.absolutize_url("http://example.com", "/this/that")
    ).to.be("http://example.com/this/that")
    expect(
      utils.absolutize_url("http://example.com", "http://example2.com/this/that")
    ).to.be("http://example2.com/this/that")
    expect(
      utils.absolutize_url("https://example.com", "/this/that")
    ).to.be("https://example.com/this/that")

  it "Checks sharing with undefined or not groups", ->
    expect(utils.sharing_is_equal({
      group_id: undefined
    }, {
      group_id: "not undefined"
    })).to.be(false)

  it "Checks equality of sharing settings: empty lists", ->
    future = new Date()
    expect(utils.sharing_is_equal({
      public_view_until: future
{'fraction_non_alphanumeric': 0.20582793709528216, 'fraction_numerical': 0.0037002775208140612, 'mean_word_length': 3.0429906542056075, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, 'https://': 4, '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': '3791265', 'n_tokens_mistral': 771, 'n_tokens_neox': 750, 'n_words': 141}