Wei Li | 614d20a | 2016-03-15 13:55:12 -0700 | [diff] [blame] | 1 | // Copyright 2016 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Dan Sinclair | e0345a4 | 2017-10-30 20:20:42 +0000 | [diff] [blame] | 5 | #include "fxjs/cjs_publicmethods.h" |
Wei Li | 614d20a | 2016-03-15 13:55:12 -0700 | [diff] [blame] | 6 | |
| 7 | #include "testing/gtest/include/gtest/gtest.h" |
| 8 | #include "testing/test_support.h" |
| 9 | |
| 10 | TEST(CJS_PublicMethods, IsNumber) { |
| 11 | // TODO(weili): Check whether results from case 0, 1, 10, 15 are intended. |
| 12 | struct { |
| 13 | const wchar_t* input; |
| 14 | bool expected; |
| 15 | } test_data[] = { |
| 16 | // Empty string. |
| 17 | {L"", true}, |
| 18 | // Only whitespaces. |
| 19 | {L" ", true}, |
| 20 | // Content with invalid characters. |
| 21 | {L"xyz00", false}, |
| 22 | {L"1%", false}, |
| 23 | // Hex string. |
| 24 | {L"0x234", false}, |
| 25 | // Signed numbers. |
| 26 | {L"+123", true}, |
| 27 | {L"-98765", true}, |
| 28 | // Numbers with whitespaces. |
| 29 | {L" 345 ", true}, |
| 30 | // Float numbers. |
| 31 | {L"-1e5", false}, |
| 32 | {L"-2e", false}, |
| 33 | {L"e-5", true}, |
| 34 | {L"0.023", true}, |
| 35 | {L".356089", true}, |
| 36 | {L"1e-9", true}, |
| 37 | {L"-1.23e+23", true}, |
| 38 | // Numbers with commas. |
| 39 | {L"1,000,000", false}, |
| 40 | {L"560,024", true}, |
| 41 | // Regular numbers. |
| 42 | {L"0", true}, |
| 43 | {L"0123", true}, |
| 44 | {L"9876123", true}, |
| 45 | }; |
| 46 | for (size_t i = 0; i < FX_ArraySize(test_data); ++i) { |
| 47 | EXPECT_EQ(test_data[i].expected, |
| 48 | CJS_PublicMethods::IsNumber(test_data[i].input)) |
| 49 | << "for case " << i; |
| 50 | } |
| 51 | } |