TestHtmlSimd.cpp (1945B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #include "gtest/gtest.h" 6 #include "mozilla/htmlaccel/htmlaccelNotInline.h" 7 8 // Match in the first half 9 const char16_t HTML_SIMD_TEST_INPUT_LOW[16] = { 10 'a', 11 0xD834, // Surrogate pair 12 0xDD65, '\n', '<', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 13 }; 14 15 // Match in the second half 16 const char16_t HTML_SIMD_TEST_INPUT_HIGH[16] = { 17 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'a', 18 0xD834, // Surrogate pair 19 0xDD65, '\n', '<', 'f', 'g', 'h', 20 }; 21 22 TEST(HtmlSimd, TestTextNodeAllowSurrogatesAndLf) 23 { 24 int32_t index = mozilla::htmlaccel::AccelerateDataFastest( 25 HTML_SIMD_TEST_INPUT_LOW, HTML_SIMD_TEST_INPUT_LOW + 16); 26 ASSERT_EQ(index, 4); 27 } 28 29 TEST(HtmlSimd, TestTextNodeAllowSurrogatesDisallowLf) 30 { 31 int32_t index = mozilla::htmlaccel::AccelerateDataViewSource( 32 HTML_SIMD_TEST_INPUT_LOW, HTML_SIMD_TEST_INPUT_LOW + 16); 33 ASSERT_EQ(index, 3); 34 } 35 36 TEST(HtmlSimd, TestTextNodeDisallowSurrogatesAndLf) 37 { 38 int32_t index = mozilla::htmlaccel::AccelerateDataLineCol( 39 HTML_SIMD_TEST_INPUT_LOW, HTML_SIMD_TEST_INPUT_LOW + 16); 40 ASSERT_EQ(index, 1); 41 } 42 43 TEST(HtmlSimd, TestTextNodeAllowSurrogatesAndLfHigh) 44 { 45 int32_t index = mozilla::htmlaccel::AccelerateDataFastest( 46 HTML_SIMD_TEST_INPUT_HIGH, HTML_SIMD_TEST_INPUT_HIGH + 16); 47 ASSERT_EQ(index, 4 + 8); 48 } 49 50 TEST(HtmlSimd, TestTextNodeAllowSurrogatesDisallowLfHigh) 51 { 52 int32_t index = mozilla::htmlaccel::AccelerateDataViewSource( 53 HTML_SIMD_TEST_INPUT_HIGH, HTML_SIMD_TEST_INPUT_HIGH + 16); 54 ASSERT_EQ(index, 3 + 8); 55 } 56 57 TEST(HtmlSimd, TestTextNodeDisallowSurrogatesAndLfHigh) 58 { 59 int32_t index = mozilla::htmlaccel::AccelerateDataLineCol( 60 HTML_SIMD_TEST_INPUT_HIGH, HTML_SIMD_TEST_INPUT_HIGH + 16); 61 ASSERT_EQ(index, 1 + 8); 62 }