<commit_before>//----------------------------------------------------------------------
//
// This source file is part of the Folktale project.
//
// Copyright (C) 2015-2016 <NAME>.
// Licensed under the MIT licence.
//
// See LICENCE for licence information.
// See CONTRIBUTORS for the list of contributors to the project.
//
//----------------------------------------------------------------------

const { property, forall} = require('jsverify');
const assert = require('assert');
const laws = require('../helpers/fantasy-land-laws');
const Maybe = require('folktale/data/maybe');
const { Just, Nothing } = Maybe;


describe('Data.Maybe', () => {

  describe('Conversions', () => {
    property('Just#fromEither', 'json', (a) => {
      return Maybe.fromEither(Just(a).toEither()).equals(Just(a));
    });
    property('Nothing#fromEither', 'json', (a) => {
      return Maybe.fromEither(Nothing().toEither()).equals(Nothing());
    });
  });

  describe('#map(f)', () => {
    property('Just(a).map(f) = Just(f(a))', 'nat', 'nat -> nat', (a, f) => {
      return Just(a).map(f).equals(Just(f(a)));
    });

    it('Nothing().map(f) = Nothing()', () => {
      let called = false;
      const f = () => { called = true };
      Nothing().map(f);
      $ASSERT(called === false);
    });
  });

  describe('#apply(a)', () => {
    property('Just(f).apply(a) = Just(f(a))', 'nat', 'nat -> nat', (a, f) => {
      return Just(f).apply(Just(a)).equals(Just(f(a)));
    });

    property('Just(f).apply(Nothing()) = Nothing()', 'nat -> nat', (f) => {
      return Just(f).apply(Nothing()).equals(Nothing());
    })

    property('Nothing().apply(a) = Nothing()', 'nat', (a) => {
      return Nothing().apply(Just(a)).equals(Nothing());
    });
  });

  describe('#of(a)', () => {
    property('Maybe.of(a) = Just(a)', 'json', (a) => {
      return Maybe.of(a).equals(Just(a));
    });
  });

  describe('#chain(f)', () => {
    property('Just(a).chain(f) = f(a)', 'json', 'json -> json', (a, f) => {
      return Just(a).chain(x => Just(f(x))).equals(Just(f(a)));
    });

    property('Nothing().chain(f) = Nothing()', 'json -> json', (f) => {
      return Nothing().chain(x => Just(f(x))).equals(Nothing());
    });
  });

  describe('#get()', () => {
    property('Just(a).get() = a', 'json', (a) => {
      return Just(a).get() === a;
    });

    it('Nothing().get() throws', () => {
      assert.throws(_ => Nothing().get());<commit_msg>(fix test) .get() → .unsafeGet()<commit_after>//----------------------------------------------------------------------
//
// This source file is part of the Folktale project.
//
// Copyright (C) 2015-2016 <NAME>.
// Licensed under the MIT licence.
//
// See LICENCE for licence information.
// See CONTRIBUTORS for the list of contributors to the project.
//
//----------------------------------------------------------------------

const { property, forall} = require('jsverify');
const assert = require('assert');
const laws = require('../helpers/fantasy-land-laws');
const Maybe = require('folktale/data/maybe');
const { Just, Nothing } = Maybe;


describe('Data.Maybe', () => {

  describe('Conversions', () => {
    property('Just#fromEither', 'json', (a) => {
      return Maybe.fromEither(Just(a).toEither()).equals(Just(a));
    });
    property('Nothing#fromEither', 'json', (a) => {
      return Maybe.fromEither(Nothing().toEither()).equals(Nothing());
    });
  });

  describe('#map(f)', () => {
    property('Just(a).map(f) = Just(f(a))', 'nat', 'nat -> nat', (a, f) => {
      return Just(a).map(f).equals(Just(f(a)));
    });

    it('Nothing().map(f) = Nothing()', () => {
      let called = false;
      const f = () => { called = true };
      Nothing().map(f);
      $ASSERT(called === false);
    });
  });

  describe('#apply(a)', () => {
    property('Just(f).apply(a) = Just(f(a))', 'nat', 'nat -> nat', (a, f) => {
      return Just(f).apply(Just(a)).equals(Just(f(a)));
    });

    property('Just(f).apply(Nothing()) = Nothing()', 'nat -> nat', (f) => {
      return Just(f).apply(Nothing()).equals(Nothing());
    })

    property('Nothing().apply(a) = Nothing()', 'nat', (a) => {
      return Nothing().apply(Just(a)).equals(Nothing());
    });
  });

  describe('#of(a)', () => {
    property('Maybe.of(a) = Just(a)', 'json', (a) => {
      return Maybe.of(a).equals(Just(a));
    });
  });

  describe('#chain(f)', () => {
    property('Just(a).chain(f) = f(a)', 'json', 'json -> json', (a, f) => {
      return Just(a).chain(x => Just(f(x))).equals(Just(f(a)));
    });

    property('Nothing().chain(f) = Nothing()', 'json -> json', (f) => {
      return Nothing().chain(x => Just(f(x))).equals(Nothing());
    });
  });

  describe('#unsafeGet()', () => {
    property('Just(a).unsafeGet() = a', 'json', (a) => {
      return Just(a).unsafeGet() === a;
    });

    it('Nothing().unsafeGet() throws', () => {
      assert.throws(_ => Nothing().unsafeGet());
{'fraction_non_alphanumeric': 0.3071153456314616, 'fraction_numerical': 0.003243462396107845, 'mean_word_length': 2.5779550398839737, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 61, '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': '1527508', 'n_tokens_mistral': 1634, 'n_tokens_neox': 1561, 'n_words': 295}