2013-07-23 23:20:44 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Soonho Kong
|
|
|
|
*/
|
2013-07-25 00:50:51 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <algorithm>
|
2013-08-22 15:20:42 +00:00
|
|
|
#include <sstream>
|
2013-09-13 23:14:24 +00:00
|
|
|
#include <utility>
|
|
|
|
#include <string>
|
2013-09-13 03:04:10 +00:00
|
|
|
#include "util/test.h"
|
|
|
|
#include "util/numerics/mpq.h"
|
|
|
|
#include "util/sexpr/format.h"
|
|
|
|
#include "util/sexpr/sexpr_fn.h"
|
|
|
|
#include "util/sexpr/options.h"
|
2013-07-23 23:20:44 +00:00
|
|
|
using namespace lean;
|
|
|
|
|
2013-07-25 00:50:51 +00:00
|
|
|
using std::cout;
|
|
|
|
using std::endl;
|
2013-07-24 01:41:56 +00:00
|
|
|
|
2013-07-23 23:20:44 +00:00
|
|
|
static void tst1() {
|
|
|
|
format f_atom1("foo");
|
|
|
|
format f_atom2("bar");
|
|
|
|
format f_atom3(1);
|
|
|
|
format f_atom4(3.1415);
|
2013-07-25 00:50:51 +00:00
|
|
|
format f1(highlight(f_atom1), f_atom2);
|
2013-08-03 02:48:24 +00:00
|
|
|
format f2{f_atom1, f_atom2, highlight(f_atom3, format::format_color::ORANGE), f_atom4};
|
2013-07-25 00:50:51 +00:00
|
|
|
format f3 = compose(f1, f2);
|
2013-07-23 23:20:44 +00:00
|
|
|
format f4 = nest(3, f3);
|
|
|
|
format f5 = line();
|
|
|
|
format f6(f4, f5);
|
2014-08-24 16:35:25 +00:00
|
|
|
format f7 = nest(10, f6 + f4 + f6 + f4);
|
2013-08-03 02:48:24 +00:00
|
|
|
format f8(f_atom1, nest(3, format(line(), f_atom1)));
|
2013-07-25 00:50:51 +00:00
|
|
|
format f9 = f7 + f8;
|
|
|
|
format f10;
|
|
|
|
f10 += f6 + f5 + f3;
|
|
|
|
format f11 = above(f1, above(above(f2, f3), f4));
|
2014-08-24 16:35:25 +00:00
|
|
|
format f12 = paren(format("a") + format("b") + format("c") + format("d"));
|
2013-07-25 00:50:51 +00:00
|
|
|
|
2014-08-19 23:28:58 +00:00
|
|
|
std::vector<pair<std::string, format>> v =
|
2013-07-25 00:50:51 +00:00
|
|
|
{{"f1", f1},
|
|
|
|
{"f2", f2},
|
|
|
|
{"f3", f3},
|
|
|
|
{"f4", f4},
|
|
|
|
{"f5", f5},
|
|
|
|
{"f6", f6},
|
|
|
|
{"f7", f7},
|
|
|
|
{"f8", f8},
|
|
|
|
{"f9", f9},
|
|
|
|
{"f10", f10},
|
|
|
|
{"f11", f11},
|
2013-08-02 01:03:51 +00:00
|
|
|
{"f12", f12},
|
2013-07-25 00:50:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
std::for_each(v.begin(), v.end(),
|
2014-08-19 23:28:58 +00:00
|
|
|
[](pair<std::string, format> const & p) {
|
2013-07-25 00:50:51 +00:00
|
|
|
cout << "---- " << p.first << " ----------" << endl
|
2013-08-03 02:48:24 +00:00
|
|
|
<< p.second << endl
|
|
|
|
<< "--------------------" << endl << endl;
|
2013-07-25 00:50:51 +00:00
|
|
|
});
|
|
|
|
|
2013-08-02 01:03:51 +00:00
|
|
|
std::vector<std::string> ss = {"Last", "weekend's", "revelation", "that", "J.K.", "Rowling", "is", "the", "author", "of", "the", "critically", "acclaimed", "and", "--", "until", "now", "--", "commercially", "unsuccessful", "crime", "novel", "The", "Cuckoo's", "Calling", "has", "electrified", "the", "book", "world", "and", "solidified", "Rowling's", "reputation", "as", "a", "genuine", "writing", "talent:", "After", "all,", "if", "she", "can", "impress", "the", "critics", "without", "the", "benefit", "of", "her", "towering", "reputation,", "then", "surely", "her", "success", "is", "deserved."};
|
2013-07-25 00:50:51 +00:00
|
|
|
|
2013-08-03 02:48:24 +00:00
|
|
|
cout << fillwords(ss.begin(), ss.end());
|
2013-08-02 01:03:51 +00:00
|
|
|
|
|
|
|
std::vector<format> sl = {f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12};
|
2013-07-25 00:50:51 +00:00
|
|
|
|
|
|
|
cout << "fill" << endl;
|
|
|
|
cout << std::string(40, '=') << endl;
|
|
|
|
pretty(cout, 60, fill(sl.begin(), sl.end()));
|
|
|
|
cout << endl;
|
|
|
|
cout << std::string(40, '=') << endl;
|
|
|
|
|
|
|
|
cout << "stack" << endl;
|
|
|
|
cout << std::string(40, '=') << endl;
|
|
|
|
pretty(cout, 60, stack(sl.begin(), sl.end()));
|
|
|
|
cout << endl;
|
|
|
|
cout << std::string(40, '=') << endl;
|
|
|
|
|
|
|
|
cout << "spread" << endl;
|
|
|
|
cout << std::string(40, '=') << endl;
|
|
|
|
pretty(cout, 60, spread(sl.begin(), sl.end()));
|
|
|
|
cout << endl;
|
|
|
|
cout << std::string(40, '=') << endl;
|
2013-07-23 23:20:44 +00:00
|
|
|
}
|
|
|
|
|
2013-08-02 05:07:28 +00:00
|
|
|
static void tst2() {
|
|
|
|
format f4 = nest(3, compose(format("foo"), compose(line(), format("bla"))));
|
|
|
|
cout << f4 << "\n";
|
|
|
|
cout << paren(f4) << "\n";
|
|
|
|
}
|
|
|
|
|
2013-08-13 23:19:30 +00:00
|
|
|
static void tst3() {
|
|
|
|
format f_atom1("foo");
|
|
|
|
format f_atom2("bar");
|
|
|
|
format f1(highlight(f_atom1), f_atom2);
|
|
|
|
cout << f1 << "\n";
|
|
|
|
cout << mk_pair(f1, options({"pp", "colors"}, false)) << "\n";
|
|
|
|
}
|
|
|
|
|
2013-08-22 15:20:42 +00:00
|
|
|
static void tst4() {
|
|
|
|
std::ostringstream s;
|
|
|
|
s << "(" << format() << ") ";
|
|
|
|
s << "(" << (format("foo") ^ format("bar")) << ") ";
|
|
|
|
s << pp(sexpr()) << " ";
|
|
|
|
s << pp(sexpr("test")) << " ";
|
|
|
|
sexpr s1(mpz(100));
|
2013-09-13 19:49:03 +00:00
|
|
|
sexpr s2(mpq(1, 2));
|
2013-08-22 15:20:42 +00:00
|
|
|
sexpr s3{s1, s2};
|
|
|
|
s << pp(s3);
|
|
|
|
std::cout << s.str() << "\n";
|
2013-09-26 02:22:36 +00:00
|
|
|
lean_assert_eq(s.str(), "() (foo bar) nil \"test\" (100 1/2)");
|
2013-08-22 15:20:42 +00:00
|
|
|
}
|
|
|
|
|
2014-02-21 01:19:03 +00:00
|
|
|
static void tst5() {
|
|
|
|
std::cout << "{" << format() << "}" << "\n";
|
|
|
|
}
|
|
|
|
|
2014-08-23 19:00:32 +00:00
|
|
|
static void tst6() {
|
|
|
|
format r = (format("test") ^ format("hello")) + line() + format("world");
|
|
|
|
std::cout << "test6\n";
|
|
|
|
std::cout << r << "\n";
|
|
|
|
std::cout << flatten(r) << "\n";
|
|
|
|
}
|
|
|
|
|
2013-07-23 23:20:44 +00:00
|
|
|
int main() {
|
2013-12-07 22:59:21 +00:00
|
|
|
save_stack_info();
|
2013-07-23 23:20:44 +00:00
|
|
|
tst1();
|
2013-08-02 05:07:28 +00:00
|
|
|
tst2();
|
2013-08-13 23:19:30 +00:00
|
|
|
tst3();
|
2013-08-22 15:20:42 +00:00
|
|
|
tst4();
|
2014-02-21 01:19:03 +00:00
|
|
|
tst5();
|
2014-08-23 19:00:32 +00:00
|
|
|
tst6();
|
2013-07-23 23:20:44 +00:00
|
|
|
return has_violations() ? 1 : 0;
|
|
|
|
}
|