Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(477)

Unified Diff: Source/core/css/parser/MediaQueryCalcParserTest.cpp

Issue 252743004: A thread safe CSS calc parser for sizes (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: removed linespace Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/css/parser/MediaQueryCalcParserTest.cpp
diff --git a/Source/core/css/parser/MediaQueryCalcParserTest.cpp b/Source/core/css/parser/MediaQueryCalcParserTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..377537fd53521941bed14938c8db28788f038fc5
--- /dev/null
+++ b/Source/core/css/parser/MediaQueryCalcParserTest.cpp
@@ -0,0 +1,44 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "core/css/parser/MediaQueryCalcParser.h"
+
+#include "core/css/parser/MediaQueryTokenizer.h"
+
+#include <gtest/gtest.h>
+
+namespace WebCore {
+
+typedef struct {
+ const char* input;
+ const int output;
+} TestCase;
+
+TEST(MediaQueryCalcParserTest, Basic)
+{
+ // The first string represents the input string.
+ // The second string represents the output string, if present.
+ // Otherwise, the output string is identical to the first string.
+ TestCase testCases[] = {
+ {"calc(500px + 10em)", 660},
+ {"calc(500px + 2 * 10em)", 820},
+ {"calc(500px + 2*10em)", 820},
+ {"calc(500px + 50%*10em)", 580},
+ {"calc(500px + (50%*10em + 13px))", 593},
+ {"calc(100vw + (50%*10em + 13px))", 593},
+ {"calc(100vh + (50%*10em + 13px))", 736},
+ {0, 0} // Do not remove the terminator line.
+ };
+
+
+ for (unsigned i = 0; testCases[i].input; ++i) {
+ Vector<MediaQueryToken> tokens;
+ MediaQueryTokenizer::tokenize(testCases[i].input, tokens);
+ int output = MediaQueryCalcParser::parse(tokens.begin(), tokens.end(), 16, 500, 643);
+ ASSERT_EQ(testCases[i].output, output);
+ }
+}
+
+} // namespace

Powered by Google App Engine
This is Rietveld 408576698