Flutter Engine
string_range_sanitization_unittests.mm File Reference
#include <Foundation/Foundation.h>
#include "flutter/fml/platform/darwin/string_range_sanitization.h"
#include "gtest/gtest.h"

Go to the source code of this file.

Functions

 TEST (StringRangeSanitizationTest, CanHandleUnicode)
 
 TEST (StringRangeSanitizationTest, HandlesInvalidRanges)
 
 TEST (StringRangeSanitizationTest, CanHandleUnicodeRange)
 
 TEST (StringRangeSanitizationTest, HandlesEndOfRange)
 

Function Documentation

◆ TEST() [1/4]

TEST ( StringRangeSanitizationTest  ,
CanHandleUnicode   
)

Definition at line 10 of file string_range_sanitization_unittests.mm.

References fml::RangeForCharacterAtIndex().

10  {
11  auto result = fml::RangeForCharacterAtIndex(@"😠", 1);
12  EXPECT_EQ(result.location, 0UL);
13  EXPECT_EQ(result.length, 2UL);
14 }
NSRange RangeForCharacterAtIndex(NSString *text, NSUInteger index)

◆ TEST() [2/4]

TEST ( StringRangeSanitizationTest  ,
HandlesInvalidRanges   
)

Definition at line 16 of file string_range_sanitization_unittests.mm.

References fml::RangeForCharacterAtIndex(), and fml::RangeForCharactersInRange().

16  {
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 }
NSRange RangeForCharactersInRange(NSString *text, NSRange range)
NSRange RangeForCharacterAtIndex(NSString *text, NSUInteger index)

◆ TEST() [3/4]

TEST ( StringRangeSanitizationTest  ,
CanHandleUnicodeRange   
)

Definition at line 26 of file string_range_sanitization_unittests.mm.

References fml::RangeForCharactersInRange().

26  {
27  auto result = fml::RangeForCharactersInRange(@"😠", NSMakeRange(1, 0));
28  EXPECT_EQ(result.location, 0UL);
29  EXPECT_EQ(result.length, 0UL);
30 }
NSRange RangeForCharactersInRange(NSString *text, NSRange range)

◆ TEST() [4/4]

TEST ( StringRangeSanitizationTest  ,
HandlesEndOfRange   
)

Definition at line 32 of file string_range_sanitization_unittests.mm.

References length, and fml::RangeForCharacterAtIndex().

32  {
33  EXPECT_EQ(fml::RangeForCharacterAtIndex(@"1234", 4).location, 4UL);
34  EXPECT_EQ(fml::RangeForCharacterAtIndex(@"1234", 4).length, 0UL);
35 }
NSRange RangeForCharacterAtIndex(NSString *text, NSUInteger index)
size_t length