1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <sal/config.h>
11 #include <test/bootstrapfixture.hxx>
13 #include <sfx2/sfxmodelfactory.hxx>
15 #include <document.hxx>
24 typedef rtl::Reference
<SmDocShell
> SmDocShellRef
;
26 class ParseTest
: public test::BootstrapFixture
29 virtual void setUp() override
;
30 virtual void tearDown() override
;
36 CPPUNIT_TEST_SUITE(ParseTest
);
37 CPPUNIT_TEST(testMinus
);
38 CPPUNIT_TEST(testNospace
);
39 CPPUNIT_TEST_SUITE_END();
41 SmDocShellRef mxDocShell
;
44 void ParseTest::setUp()
46 BootstrapFixture::setUp();
48 mxDocShell
= new SmDocShell(SfxModelFlags::EMBEDDED_OBJECT
|
49 SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS
|
50 SfxModelFlags::DISABLE_DOCUMENT_RECOVERY
);
53 void ParseTest::tearDown()
56 mxDocShell
->DoClose();
57 BootstrapFixture::tearDown();
61 * This shows that input "-" is recognized as a separate token even when
62 * it is immediately followed by a number.
64 void ParseTest::testMinus()
66 auto pNode
= SmParser5().Parse(u
"-1.2"_ustr
);
67 CPPUNIT_ASSERT_EQUAL(size_t(1), pNode
->GetNumSubNodes());
68 const SmNode
*pNode0
= pNode
->GetSubNode(0);
69 CPPUNIT_ASSERT(pNode0
);
70 CPPUNIT_ASSERT_EQUAL(SmNodeType::Line
, pNode0
->GetType());
71 CPPUNIT_ASSERT_EQUAL(size_t(1), pNode0
->GetNumSubNodes());
72 const SmNode
*pNode00
= pNode0
->GetSubNode(0);
73 CPPUNIT_ASSERT(pNode00
);
74 CPPUNIT_ASSERT_EQUAL(SmNodeType::UnHor
, pNode00
->GetType());
75 CPPUNIT_ASSERT_EQUAL(size_t(2), pNode00
->GetNumSubNodes());
76 const SmNode
*pNode000
= pNode00
->GetSubNode(0);
77 CPPUNIT_ASSERT(pNode000
);
78 CPPUNIT_ASSERT_EQUAL(SmNodeType::Math
, pNode000
->GetType());
79 // GetText() vs GetToken().aText
80 CPPUNIT_ASSERT_EQUAL(OUString(MS_MINUS
),
81 static_cast<const SmMathSymbolNode
*>(pNode000
)->GetText());
82 CPPUNIT_ASSERT_EQUAL(u
"-"_ustr
,
83 static_cast<const SmMathSymbolNode
*>(pNode000
)->GetToken().aText
);
84 const SmNode
*pNode001
= pNode00
->GetSubNode(1);
85 CPPUNIT_ASSERT(pNode001
);
86 CPPUNIT_ASSERT_EQUAL(SmNodeType::Text
, pNode001
->GetType());
87 // GetText() vs GetToken().aText
88 CPPUNIT_ASSERT(static_cast<const SmTextNode
*>(pNode001
)->GetText().isEmpty());
89 CPPUNIT_ASSERT_EQUAL(u
"1.2"_ustr
,
90 static_cast<const SmTextNode
*>(pNode001
)->GetToken().aText
);
94 * This shows that "nospace" turns off the expression's IsUseExtraSpaces(),
95 * but leaves its descendants' flag on.
97 void ParseTest::testNospace()
99 auto pNode
= SmParser5().Parse(u
"nospace{ nitalic d {F(x) G(x)} }"_ustr
);
100 CPPUNIT_ASSERT_EQUAL(size_t(1), pNode
->GetNumSubNodes());
101 const SmNode
*pNode0
= pNode
->GetSubNode(0);
102 CPPUNIT_ASSERT(pNode0
);
103 CPPUNIT_ASSERT_EQUAL(SmNodeType::Line
, pNode0
->GetType());
104 CPPUNIT_ASSERT_EQUAL(size_t(1), pNode0
->GetNumSubNodes());
105 const SmNode
*pNode00
= pNode0
->GetSubNode(0);
106 CPPUNIT_ASSERT(pNode00
);
107 CPPUNIT_ASSERT_EQUAL(SmNodeType::Expression
, pNode00
->GetType());
108 CPPUNIT_ASSERT(!static_cast<const SmExpressionNode
*>(pNode00
)->IsUseExtraSpaces());
109 CPPUNIT_ASSERT_EQUAL(size_t(2), pNode00
->GetNumSubNodes());
110 const SmNode
*pNode000
= pNode00
->GetSubNode(0);
111 CPPUNIT_ASSERT(pNode000
);
112 CPPUNIT_ASSERT_EQUAL(SmNodeType::Font
, pNode000
->GetType());
113 CPPUNIT_ASSERT_EQUAL(u
"nitalic"_ustr
,
114 static_cast<const SmFontNode
*>(pNode000
)->GetToken().aText
);
115 const SmNode
*pNode001
= pNode00
->GetSubNode(1);
116 CPPUNIT_ASSERT(pNode001
);
117 CPPUNIT_ASSERT_EQUAL(SmNodeType::Expression
, pNode001
->GetType());
118 CPPUNIT_ASSERT(static_cast<const SmExpressionNode
*>(pNode001
)->IsUseExtraSpaces());
119 CPPUNIT_ASSERT_EQUAL(size_t(2), pNode00
->GetNumSubNodes());
122 CPPUNIT_TEST_SUITE_REGISTRATION(ParseTest
);
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */