aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/scheme/ut_utils/scheme_ut_utils.cpp
blob: b520eceab52fa910c35bceffb9511b2e0c29e82a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "scheme_ut_utils.h" 
 
#include <library/cpp/colorizer/colors.h>
 
#include <util/stream/str.h> 
 
namespace NSc { 
    namespace NUt { 
        NSc::TValue AssertFromJson(TStringBuf val) { 
            try { 
                return TValue::FromJsonThrow(val); 
            } catch (const TSchemeParseException& e) { 
                TStringStream s; 
                NColorizer::TColors colors; 
                s << "\n"
                  << colors.YellowColor() << "Reason:" << colors.OldColor() << "\n"
                  << e.Reason;
                s << "\n"
                  << colors.YellowColor() << "Where:" << colors.OldColor() << "\n"
                  << val.SubStr(0, e.Offset) << colors.RedColor() << val.SubStr(e.Offset) << colors.OldColor() << "\n";
                UNIT_FAIL_IMPL("could not parse json", s.Str()); 
                return NSc::Null(); 
            } catch (const yexception& e) { 
                TStringStream s; 
                s << '\n'
                  << val;
                UNIT_FAIL_IMPL("could not parse json", s.Str()); 
                return NSc::Null(); 
            } 
        } 
 
        void AssertScheme(const TValue& expected, const TValue& actual) { 
            UNIT_ASSERT_JSON_EQ_JSON(actual, expected); 
        } 
 
        void AssertSchemeJson(TStringBuf expected, const NSc::TValue& actual) { 
            UNIT_ASSERT_JSON_EQ_JSON(actual, expected); 
        } 
 
        void AssertJsonJson(TStringBuf expected, TStringBuf actual) { 
            UNIT_ASSERT_JSON_EQ_JSON(actual, expected); 
        } 
    } 
}