64 lines
1.7 KiB
C++
64 lines
1.7 KiB
C++
#include <gtest/gtest.h>
|
|
#include "../src/serializer/ast_serializer.hpp"
|
|
|
|
using namespace pdfengine;
|
|
|
|
TEST(AstSerializerTest, SimpleOperations) {
|
|
Operation opTd;
|
|
opTd.op = "Td";
|
|
|
|
auto xNode = std::make_shared<AstNode>(AstNodeType::Number);
|
|
xNode->numberValue = 10.5;
|
|
|
|
auto yNode = std::make_shared<AstNode>(AstNodeType::Number);
|
|
yNode->numberValue = 20.0;
|
|
|
|
opTd.operands.push_back(xNode);
|
|
opTd.operands.push_back(yNode);
|
|
|
|
AstSerializer serializer;
|
|
std::string result = serializer.serialize({opTd});
|
|
|
|
EXPECT_EQ(result, "10.5 20 Td\n");
|
|
}
|
|
|
|
TEST(AstSerializerTest, StringEscaping) {
|
|
Operation opTj;
|
|
opTj.op = "Tj";
|
|
|
|
auto strNode = std::make_shared<AstNode>(AstNodeType::String);
|
|
strNode->stringValue = "Hello (World)";
|
|
|
|
opTj.operands.push_back(strNode);
|
|
|
|
AstSerializer serializer;
|
|
std::string result = serializer.serialize({opTj});
|
|
|
|
EXPECT_EQ(result, "(Hello \\(World\\)) Tj\n");
|
|
}
|
|
|
|
TEST(AstSerializerTest, ArraySerialization) {
|
|
Operation opTJ;
|
|
opTJ.op = "TJ";
|
|
|
|
auto arrNode = std::make_shared<AstNode>(AstNodeType::Array);
|
|
|
|
auto str1 = std::make_shared<AstNode>(AstNodeType::String);
|
|
str1->stringValue = "He";
|
|
auto num = std::make_shared<AstNode>(AstNodeType::Number);
|
|
num->numberValue = 120;
|
|
auto str2 = std::make_shared<AstNode>(AstNodeType::String);
|
|
str2->stringValue = "llo";
|
|
|
|
arrNode->arrayItems.push_back(str1);
|
|
arrNode->arrayItems.push_back(num);
|
|
arrNode->arrayItems.push_back(str2);
|
|
|
|
opTJ.operands.push_back(arrNode);
|
|
|
|
AstSerializer serializer;
|
|
std::string result = serializer.serialize({opTJ});
|
|
|
|
EXPECT_EQ(result, "[ (He) 120 (llo) ] TJ\n");
|
|
}
|