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
5 #include "fxjs/cjs_publicmethods.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
TEST(CJS_PublicMethods,IsNumber)9 TEST(CJS_PublicMethods, IsNumber) {
10 // TODO(weili): Check whether results from case 0, 1, 10, 15 are intended.
11 struct {
12 const wchar_t* input;
13 bool expected;
14 } test_data[] = {
15 // Empty string.
16 {L"", true},
17 // Only whitespaces.
18 {L" ", true},
19 // Content with invalid characters.
20 {L"xyz00", false},
21 {L"1%", false},
22 // Hex string.
23 {L"0x234", false},
24 // Signed numbers.
25 {L"+123", true},
26 {L"-98765", true},
27 // Numbers with whitespaces.
28 {L" 345 ", true},
29 // Float numbers.
30 {L"-1e5", false},
31 {L"-2e", false},
32 {L"e-5", true},
33 {L"0.023", true},
34 {L".356089", true},
35 {L"1e-9", true},
36 {L"-1.23e+23", true},
37 // Numbers with commas.
38 {L"1,000,000", false},
39 {L"560,024", true},
40 // Regular numbers.
41 {L"0", true},
42 {L"0123", true},
43 {L"9876123", true},
44 };
45 for (size_t i = 0; i < FX_ArraySize(test_data); ++i) {
46 EXPECT_EQ(test_data[i].expected,
47 CJS_PublicMethods::IsNumber(test_data[i].input))
48 << "for case " << i;
49 }
50 }
51