mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix string token serialization
Add more tests
This commit is contained in:
parent
43616dd0d6
commit
66343bc85e
@ -297,11 +297,13 @@ class Token {
|
||||
|
||||
void serialize_string(std::u32string &out) const {
|
||||
const char32_t delim = text.find('"') == std::u32string::npos ? '"' : '\'';
|
||||
out.push_back(delim);
|
||||
for (const auto ch : text) {
|
||||
if (ch == '\n') out.append({'\\', '\n'});
|
||||
else if (ch == delim || ch == '\\') serialize_escaped_char(ch, out);
|
||||
else out.push_back(ch);
|
||||
}
|
||||
out.push_back(delim);
|
||||
}
|
||||
|
||||
public:
|
||||
@ -313,7 +315,7 @@ class Token {
|
||||
Token(const TokenType type, const char32_t ch, size_t out_pos) :
|
||||
type(type), text(), unit_at(0), out_pos(out_pos) {
|
||||
text.reserve(16);
|
||||
text.push_back(ch);
|
||||
if (ch) text.push_back(ch);
|
||||
}
|
||||
|
||||
Token(const Token& other) :
|
||||
|
@ -23,7 +23,15 @@ class TestTransform(SimpleTest):
|
||||
self.ae(transform_properties(src, is_declaration=is_declaration, url_callback=url_callback), expected)
|
||||
|
||||
d(r'f\ont-s\69z\65 : 16\px', 'font-size: 1rem')
|
||||
d('font -size: 16px', 'font -size: 16px')
|
||||
d('font-size: 16px', 'font-size: 1rem')
|
||||
d('fOnt-size :16px', 'fOnt-size :1rem')
|
||||
d('font-size:2%', 'font-size:2%')
|
||||
d('font-size: 72pt; color: red; font-size: 2in', 'font-size: 6rem; color: red; font-size: 12rem')
|
||||
d('font-size: 72pt; margin: 20px; font-size: 2in', 'font-size: 6rem; margin: 20px; font-size: 12rem')
|
||||
d(r'''font: "some 'name" 32px''', 'font: "some \'name" 2rem')
|
||||
d(r'''font: 'some "name' 32px''', 'font: \'some "name\' 2rem')
|
||||
d(r'''font: 'some \n ame' 32px''', 'font: "some n ame" 2rem')
|
||||
d('''font: 'some \\\nname' 32px''', 'font: "some name" 2rem')
|
||||
d('font: sans-serif 16px/3', 'font: sans-serif 1rem/3')
|
||||
|
||||
d('-epub-writing-mode: a; -webkit-writing-mode: b; writing-mode: c', 'writing-mode: a; writing-mode: b; writing-mode: c')
|
||||
|
Loading…
x
Reference in New Issue
Block a user