Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
string_range_sanitization_unittests.mm
Go to the documentation of this file.
1// Copyright 2013 The Flutter 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 <Foundation/Foundation.h>
6
7#include "flutter/fml/platform/darwin/string_range_sanitization.h"
8#include "gtest/gtest.h"
9
10TEST(StringRangeSanitizationTest, CanHandleUnicode) {
11 auto result = fml::RangeForCharacterAtIndex(@"😠", 1);
12 EXPECT_EQ(result.location, 0UL);
13 EXPECT_EQ(result.length, 2UL);
14}
15
16TEST(StringRangeSanitizationTest, HandlesInvalidRanges) {
17 auto ns_not_found = static_cast<unsigned long>(NSNotFound);
18 EXPECT_EQ(fml::RangeForCharacterAtIndex(@"😠", 3).location, ns_not_found);
19 EXPECT_EQ(fml::RangeForCharacterAtIndex(@"😠", -1).location, ns_not_found);
20 EXPECT_EQ(fml::RangeForCharacterAtIndex(nil, 0).location, ns_not_found);
21 EXPECT_EQ(fml::RangeForCharactersInRange(@"😠", NSMakeRange(1, 2)).location, ns_not_found);
22 EXPECT_EQ(fml::RangeForCharactersInRange(@"😠", NSMakeRange(3, 0)).location, ns_not_found);
23 EXPECT_EQ(fml::RangeForCharactersInRange(nil, NSMakeRange(0, 0)).location, ns_not_found);
24}
25
26TEST(StringRangeSanitizationTest, CanHandleUnicodeRange) {
27 auto result = fml::RangeForCharactersInRange(@"😠", NSMakeRange(1, 0));
28 EXPECT_EQ(result.location, 0UL);
29 EXPECT_EQ(result.length, 0UL);
30}
31
32TEST(StringRangeSanitizationTest, HandlesEndOfRange) {
33 EXPECT_EQ(fml::RangeForCharacterAtIndex(@"1234", 4).location, 4UL);
34 EXPECT_EQ(fml::RangeForCharacterAtIndex(@"1234", 4).length, 0UL);
35}
#define TEST(S, s, D, expected)
GAsyncResult * result
size_t length
NSRange RangeForCharacterAtIndex(NSString *text, NSUInteger index)
NSRange RangeForCharactersInRange(NSString *text, NSRange range)