2013-07-21 22:08:14 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
2013-08-22 15:48:52 +00:00
|
|
|
#include <cstring>
|
|
|
|
#include <sstream>
|
2013-09-13 03:04:10 +00:00
|
|
|
#include "util/test.h"
|
|
|
|
#include "util/name.h"
|
2013-09-13 19:49:03 +00:00
|
|
|
using namespace lean;
|
2013-07-21 22:08:14 +00:00
|
|
|
|
|
|
|
static void tst1() {
|
|
|
|
name n("foo");
|
|
|
|
lean_assert(n == name("foo"));
|
|
|
|
lean_assert(n != name(1));
|
|
|
|
lean_assert(name(n, 1) != name(n, 2));
|
|
|
|
lean_assert(name(n, 1) == name(n, 1));
|
|
|
|
lean_assert(name(name(n, 1), 2) != name(name(n, 1), 1));
|
|
|
|
lean_assert(name(name(n, 1), 1) == name(name(n, 1), 1));
|
|
|
|
lean_assert(name(name(n, 2), 1) != name(name(n, 1), 1));
|
|
|
|
lean_assert(name(name(n, "bla"), 1) == name(name(n, "bla"), 1));
|
|
|
|
lean_assert(name(name(n, "foo"), 1) != name(name(n, "bla"), 1));
|
|
|
|
lean_assert(name(name(name("f"), "bla"), 1) != name(name(n, "bla"), 1));
|
|
|
|
lean_assert(n != name());
|
2013-07-22 11:14:01 +00:00
|
|
|
lean_assert(name().kind() == name_kind::ANONYMOUS);
|
2013-07-21 22:08:14 +00:00
|
|
|
lean_assert(name(name(), "foo") == name("foo"));
|
2013-07-21 22:56:18 +00:00
|
|
|
|
|
|
|
lean_assert(name(n, 1) < name(n, 2));
|
2013-09-13 19:49:03 +00:00
|
|
|
std::cout << "cmp(" << name(n, 1) << ", " << name(n, 2) << ") = " << cmp(name(n, 1), name(n, 2)) << "\n";
|
2013-07-21 22:56:18 +00:00
|
|
|
lean_assert(!(name(n, 1) >= name(n, 2)));
|
|
|
|
lean_assert(name(n, 1) < name(name(n, 1), 1));
|
|
|
|
lean_assert(n < name(n, 1));
|
|
|
|
lean_assert(name(n, 2) > name(name(n, 1), 1));
|
|
|
|
lean_assert(name(name("aa"), 2) < name(name(n, 1), 1));
|
|
|
|
lean_assert(name(n, "aaa") < name(n, "xxx"));
|
|
|
|
lean_assert(name(n, 1) < name(n, "xxx"));
|
|
|
|
lean_assert(name(n, 1) < name(name(n, "xxx"), 1));
|
|
|
|
lean_assert(name() < name(name(n, "xxx"), 1));
|
|
|
|
lean_assert(name(1) < name(name(n, "xxx"), 1));
|
|
|
|
lean_assert(name(1) < name(2));
|
|
|
|
lean_assert(name(2) > name(1));
|
|
|
|
lean_assert(name(1) > name());
|
|
|
|
lean_assert(name(2) < name(name("foo"), 1));
|
|
|
|
lean_assert(name(0u) < name(name(1), "foo"));
|
|
|
|
lean_assert(name(2) > name(name(1), "foo"));
|
2013-07-21 22:08:14 +00:00
|
|
|
}
|
|
|
|
|
2013-07-24 18:00:29 +00:00
|
|
|
static name mk_big_name(unsigned num) {
|
|
|
|
name n("foo");
|
|
|
|
for (unsigned i = 0; i < num; i++) {
|
|
|
|
n = name(n, "bla");
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tst2() {
|
|
|
|
name n1 = mk_big_name(2000);
|
|
|
|
name n2 = mk_big_name(2000);
|
|
|
|
lean_assert(n1.hash() == n2.hash());
|
|
|
|
for (unsigned i = 0; i < 10000; i++)
|
|
|
|
n1.hash();
|
|
|
|
std::cout << "n1.hash(): " << n1.hash() << "\n";
|
|
|
|
}
|
|
|
|
|
2013-08-09 00:05:11 +00:00
|
|
|
static void tst3() {
|
|
|
|
name n{"foo", "bla", "tst"};
|
|
|
|
std::cout << n << "\n";
|
|
|
|
lean_assert(n == name(name(name("foo"), "bla"), "tst"));
|
|
|
|
}
|
|
|
|
|
2013-08-19 18:43:09 +00:00
|
|
|
static void tst4() {
|
|
|
|
lean_assert(is_prefix_of(name{"foo", "bla"}, name{"foo", "bla"}));
|
|
|
|
lean_assert(is_prefix_of(name{"foo", "bla"}, name{"foo", "bla", "foo"}));
|
|
|
|
lean_assert(is_prefix_of(name{"foo"}, name{"foo", "bla", "foo"}));
|
|
|
|
lean_assert(!is_prefix_of(name{"foo"}, name{"fo", "bla", "foo"}));
|
|
|
|
lean_assert(!is_prefix_of(name{"foo", "bla", "foo"}, name{"foo", "bla"}));
|
|
|
|
lean_assert(is_prefix_of(name{"foo", "bla"}, name(name{"foo", "bla"}, 0u)));
|
|
|
|
lean_assert(is_prefix_of(name(name(0u), 1u), name(name(0u), 1u)));
|
|
|
|
lean_assert(!is_prefix_of(name(name(0u), 3u), name(name(0u), 1u)));
|
|
|
|
lean_assert(is_prefix_of(name(name(0u), 1u), name(name(name(0u), 1u), "foo")));
|
|
|
|
lean_assert(!is_prefix_of(name(name(2u), 1u), name(name(name(0u), 1u), "foo")));
|
|
|
|
lean_assert(!is_prefix_of(name(name(0u), 3u), name(name(name(0u), 1u), "foo")));
|
|
|
|
lean_assert(!is_prefix_of(name(name("bla"), 1u), name(name(name(0u), 1u), "foo")));
|
|
|
|
}
|
|
|
|
|
2013-08-22 15:48:52 +00:00
|
|
|
static void tst5() {
|
|
|
|
name n(0u);
|
|
|
|
lean_assert(n.size() == 1);
|
|
|
|
lean_assert(name().size() > 0);
|
|
|
|
lean_assert(name({"foo", "bla", "boing"}).get_prefix() == name({"foo", "bla"}));
|
|
|
|
lean_assert(!name({"foo", "bla", "boing"}).is_atomic());
|
|
|
|
lean_assert(name({"foo"}).is_atomic());
|
|
|
|
lean_assert(strcmp(name({"foo", "bla", "boing"}).get_string(), "boing") == 0);
|
|
|
|
lean_assert(name(name(0u), 1u).get_numeral() == 1u);
|
|
|
|
lean_assert(name(2u).get_numeral() == 2u);
|
|
|
|
lean_assert(name::anonymous().is_anonymous());
|
|
|
|
name n1("foo");
|
|
|
|
name n2 = n1;
|
|
|
|
lean_assert(n2 == n1);
|
|
|
|
std::cout << name::anonymous() << "\n";
|
|
|
|
std::cout << name({"foo", "bla", "boing"}).get_prefix() << "\n";
|
|
|
|
lean_assert(name("foo").is_string());
|
|
|
|
lean_assert(name(0u).is_numeral());
|
|
|
|
lean_assert(name(name(0u), "foo").is_string());
|
|
|
|
lean_assert(name(name("foo"), 0u).is_numeral());
|
|
|
|
lean_assert(name(name(0u), "foo").get_prefix().is_numeral());
|
|
|
|
lean_assert(name(name("foo"), 0u).get_prefix().is_string());
|
|
|
|
}
|
|
|
|
|
2013-09-03 17:09:19 +00:00
|
|
|
static void tst6() {
|
|
|
|
lean_assert(name({"foo", "bla"}).is_safe_ascii());
|
|
|
|
lean_assert(name(123u).is_safe_ascii());
|
|
|
|
lean_assert(name(name(name(230u), "bla"), "foo").is_safe_ascii());
|
|
|
|
lean_assert(!name({"foo", "b\u2200aaa"}).is_safe_ascii());
|
|
|
|
lean_assert(!name({"\u2200", "boo"}).is_safe_ascii());
|
|
|
|
lean_assert(!name(name(name(230u), "bla\u2200"), "foo").is_safe_ascii());
|
|
|
|
}
|
|
|
|
|
2013-09-03 18:07:28 +00:00
|
|
|
static void tst7() {
|
|
|
|
lean_assert(name("foo") + name("bla") == name({"foo", "bla"}));
|
|
|
|
lean_assert(name("foo") + name({"bla", "test"}) == name({"foo", "bla", "test"}));
|
|
|
|
lean_assert(name({"foo", "hello"}) + name({"bla", "test"}) == name({"foo", "hello", "bla", "test"}));
|
|
|
|
lean_assert(name("foo") + (name(10u) + name({"bla", "test"})) == name(name(name(name("foo"), 10u), "bla"), "test"));
|
|
|
|
lean_assert(name() + name({"bla", "test"}) == name({"bla", "test"}));
|
|
|
|
lean_assert(name({"bla", "test"}) + name() == name({"bla", "test"}));
|
|
|
|
lean_assert(name(10u) + name(20u) == name(name(10u), 20u));
|
|
|
|
}
|
|
|
|
|
2013-07-21 22:08:14 +00:00
|
|
|
int main() {
|
|
|
|
tst1();
|
2013-07-24 18:00:29 +00:00
|
|
|
tst2();
|
2013-08-09 00:05:11 +00:00
|
|
|
tst3();
|
2013-08-19 18:43:09 +00:00
|
|
|
tst4();
|
2013-08-22 15:48:52 +00:00
|
|
|
tst5();
|
2013-09-03 17:09:19 +00:00
|
|
|
tst6();
|
2013-09-03 18:07:28 +00:00
|
|
|
tst7();
|
2013-07-21 22:08:14 +00:00
|
|
|
return has_violations() ? 1 : 0;
|
|
|
|
}
|