<commit_before>// This file is part of the "x0" project, http://github.com/christianparpart/x0>
//   (c) 2009-2016 <NAME> <<EMAIL>>
//
// Licensed under the MIT License (the "License"); you may not use this
// file except in compliance with the License. You may obtain a copy of
// the License at: http://opensource.org/licenses/MIT

#include <xzero/testing.h>
#include <xzero/Option.h>

using xzero::Option;
using xzero::Some;
using xzero::None;

TEST(Option, ctor0) {
  Option<int> x;

  ASSERT_TRUE(x.isNone());
}

TEST(Option, ctorNone) {
  Option<int> x = None(); // invokes the ctor Option(const None&)

  ASSERT_TRUE(x.isNone());
}

struct Movable {
  Movable(int v) : value(v) { }
  Movable(const Movable& m) : value(m.value) { }
  Movable(Movable&& m) : value(m.value) { m.value = -1; }
  Movable& operator=(Movable&& m) {
    value = m.value;
    m.value = -1;
    return *this;
  }
  int value;
};

TEST(Option, ctorMoveValue) {
  Movable i = 42;
  Option<Movable> x = std::move(i);

  ASSERT_TRUE(x.isSome());
  ASSERT_EQ(42, x->value);
  ASSERT_EQ(-1, i.value);
}

TEST(Option, moveAssign) {
  auto a = Some(Movable(42));
  auto b = Some(Movable(13));

  a = std::move(b);

  ASSERT_EQ(13, a.get().value);
  ASSERT_TRUE(b == None());
}

TEST(Option, isNone) {
  Option<int> x = None();

  ASSERT_TRUE(x.isNone());
}

TEST(Option, isSome) {
  Option<int> x = 42;
  ASSERT_FALSE(x.isNone());
  ASSERT_TRUE(x.isSome());
}

TEST(Option, operatorBool) {
  Option<int> x = 42;
  ASSERT_FALSE(!x);
  ASSERT_TRUE(x);
}

TEST(Option, operatorEqu) {
  ASSERT_TRUE(Some(42) == Some(42));
  ASSERT_FALSE(Some(13) == Some(42));
  ASSERT_FALSE(Some(13) == None());
}

TEST(Option, operatorNe) {
  ASSERT_TRUE(Some(13) != Some(42));
  ASSERT_FALSE(Some(42) != Some(42));
  ASSERT_TRUE(Some(13) != None());
}

TEST(Option, getSome) {
  Option<int> x = 42;
  ASSERT_EQ(42, x.get());
}

TEST(Option, getNone) {
  Option<int> x = None();

  EXPECT_ANY_THROW(x.get());
  EXPECT_ANY_THROW(*x);
}

TEST(Option, clear) {
  Option<int> x = 42;

  x.clear();

  ASSERT_TRUE(x.isNone());
}

TEST(Option, onSome) {
  int retrievedValue = 0;

  Some(42).onSome([&](int i) {
    retrievedValue = i;
  }).onNone([&]() {
    retrievedValue = -1;
  });

  ASSERT_EQ(42, retrievedValue);
}

TEST(Option, onNone) {
  int retrievedValue = 0;

  Option<int>().onSome([&](int i) {
    retrievedValue = i;
  }).onNone([&]() {
    retrievedValue = -1;
  });

  ASSERT_EQ(-1, retrievedValue);
}<commit_msg>[test] Option: prefer EXPECT_* over ASSERT_*<commit_after>// This file is part of the "x0" project, http://github.com/christianparpart/x0>
//   (c) 2009-2016 <NAME> <<EMAIL>>
//
// Licensed under the MIT License (the "License"); you may not use this
// file except in compliance with the License. You may obtain a copy of
// the License at: http://opensource.org/licenses/MIT

#include <xzero/testing.h>
#include <xzero/Option.h>

using xzero::Option;
using xzero::Some;
using xzero::None;

TEST(Option, ctor0) {
  Option<int> x;

  EXPECT_TRUE(x.isNone());
}

TEST(Option, ctorNone) {
  Option<int> x = None(); // invokes the ctor Option(const None&)

  EXPECT_TRUE(x.isNone());
}

struct Movable {
  Movable(int v) : value(v) { }
  Movable(const Movable& m) : value(m.value) { }
  Movable(Movable&& m) : value(m.value) { m.value = -1; }
  Movable& operator=(Movable&& m) {
    value = m.value;
    m.value = -1;
    return *this;
  }
  int value;
};

TEST(Option, ctorMoveValue) {
  Movable i = 42;
  Option<Movable> x = std::move(i);

  EXPECT_TRUE(x.isSome());
  EXPECT_EQ(42, x->value);
  EXPECT_EQ(-1, i.value);
}

TEST(Option, moveAssign) {
  auto a = Some(Movable(42));
  auto b = Some(Movable(13));

  a = std::move(b);

  EXPECT_EQ(13, a.get().value);
  EXPECT_TRUE(b == None());
}

TEST(Option, isNone) {
  Option<int> x = None();

  EXPECT_TRUE(x.isNone());
}

TEST(Option, isSome) {
  Option<int> x = 42;
  EXPECT_FALSE(x.isNone());
  EXPECT_TRUE(x.isSome());
}

TEST(Option, operatorBool) {
  Option<int> x = 42;
  EXPECT_FALSE(!x);
  EXPECT_TRUE(x);
}

TEST(Option, operatorEqu) {
  EXPECT_TRUE(Some(42) == Some(42));
  EXPECT_FALSE(Some(13) == Some(42));
  EXPECT_FALSE(Some(13) == None());
}

TEST(Option, operatorNe) {
  EXPECT_TRUE(Some(13) != Some(42));
  EXPECT_FALSE(Some(42) != Some(42));
  EXPECT_TRUE(Some(13) != None());
}

TEST(Option, getSome) {
  Option<int> x = 42;
  EXPECT_EQ(42, x.get());
}

TEST(Option, getNone) {
  Option<int> x = None();

  EXPECT_ANY_THROW(x.get());
  EXPECT_ANY_THROW(*x);
}

TEST(Option, clear) {
  Option<int> x = 42;

  x.clear();

  EXPECT_TRUE(x.isNone());
}

TEST(Option, onSome) {
  int retrievedValue = 0;

  Some(42).onSome([&](int i) {
    retrievedValue = i;
  }).onNone([&]() {
    retrievedValue = -1;
  });

  EXPECT_EQ(42, retrievedValue);
}

TEST(Option, onNone) {
  int retrievedValue = 0;

  Option<int>().onSome([&](int i) {
    retrievedValue = i;
  }).onNone([&]() {
    retrievedValue = -1;
  });

  EXPECT_EQ(-1, retrievedValue);
}
{'fraction_non_alphanumeric': 0.19302465423932652, 'fraction_numerical': 0.025255562236921228, 'mean_word_length': 3.873046875, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 37, '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': '1648697', 'n_tokens_mistral': 2081, 'n_tokens_neox': 1986, 'n_words': 417}