Add format tests
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
3c5f993191
commit
6272408f12
2 changed files with 27 additions and 10 deletions
|
@ -6,10 +6,12 @@ Author: Soonho Kong
|
|||
*/
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include "format.h"
|
||||
#include "test.h"
|
||||
#include "sexpr_funcs.h"
|
||||
#include "options.h"
|
||||
#include "mpq.h"
|
||||
using namespace lean;
|
||||
|
||||
using std::cout;
|
||||
|
@ -98,9 +100,24 @@ static void tst3() {
|
|||
cout << mk_pair(f1, options({"pp", "colors"}, false)) << "\n";
|
||||
}
|
||||
|
||||
static void tst4() {
|
||||
std::ostringstream s;
|
||||
s << "(" << format() << ") ";
|
||||
s << "(" << (format("foo") ^ format("bar")) << ") ";
|
||||
s << pp(sexpr()) << " ";
|
||||
s << pp(sexpr("test")) << " ";
|
||||
sexpr s1(mpz(100));
|
||||
sexpr s2(mpq(1,2));
|
||||
sexpr s3{s1, s2};
|
||||
s << pp(s3);
|
||||
std::cout << s.str() << "\n";
|
||||
lean_assert(s.str() == "() (foo bar) nil \"test\" (100 1/2)");
|
||||
}
|
||||
|
||||
int main() {
|
||||
tst1();
|
||||
tst2();
|
||||
tst3();
|
||||
tst4();
|
||||
return has_violations() ? 1 : 0;
|
||||
}
|
||||
|
|
|
@ -63,8 +63,8 @@ std::ostream & layout(std::ostream & out, bool colors, sexpr const & s) {
|
|||
case format::format_kind::CHOICE:
|
||||
case format::format_kind::COMPOSE:
|
||||
case format::format_kind::FLAT_COMPOSE:
|
||||
lean_unreachable();
|
||||
break;
|
||||
lean_unreachable(); // LCOV_EXCL_LINE
|
||||
break; // LCOV_EXCL_LINE
|
||||
|
||||
case format::format_kind::NIL:
|
||||
out << "";
|
||||
|
@ -189,8 +189,8 @@ sexpr format::flatten(sexpr const & s) {
|
|||
case format_kind::COLOR_END:
|
||||
return s;
|
||||
}
|
||||
lean_unreachable();
|
||||
return s;
|
||||
lean_unreachable(); // LCOV_EXCL_LINE
|
||||
return s; // LCOV_EXCL_LINE
|
||||
}
|
||||
format format::flatten(format const & f){
|
||||
return format(flatten(f.m_value));
|
||||
|
@ -296,8 +296,8 @@ int format::space_upto_line_break(sexpr const & s, int available, bool & found_n
|
|||
return space_upto_line_break(x, available, found_newline);
|
||||
}
|
||||
}
|
||||
lean_unreachable();
|
||||
return 0;
|
||||
lean_unreachable(); // LCOV_EXCL_LINE
|
||||
return 0; // LCOV_EXCL_LINE
|
||||
}
|
||||
|
||||
sexpr format::be(unsigned w, unsigned k, sexpr const & s) {
|
||||
|
@ -352,8 +352,8 @@ sexpr format::be(unsigned w, unsigned k, sexpr const & s) {
|
|||
}
|
||||
}
|
||||
}
|
||||
lean_unreachable();
|
||||
return sexpr();
|
||||
lean_unreachable(); // LCOV_EXCL_LINE
|
||||
return sexpr(); // LCOV_EXCL_LINE
|
||||
}
|
||||
|
||||
sexpr format::best(unsigned w, unsigned k, sexpr const & s) {
|
||||
|
@ -423,8 +423,8 @@ struct sexpr_pp_fn {
|
|||
}
|
||||
}
|
||||
}}
|
||||
lean_unreachable();
|
||||
return format();
|
||||
lean_unreachable(); // LCOV_EXCL_LINE
|
||||
return format(); // LCOV_EXCL_LINE
|
||||
}
|
||||
|
||||
format operator()(sexpr const & s) {
|
||||
|
|
Loading…
Reference in a new issue