-
Notifications
You must be signed in to change notification settings - Fork 24.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve correctness of textTransform: capitalize (#47219)
Summary: Pull Request resolved: #47219 We received reports that textTransform does not correctly match the web behaviour for capitalize, eg. capitalized characters should not be lowercased when using `capitalize`. Example input: 'hello WORLD', should become 'Hello WORLD'. Changelog: [General][Fixed] TextTransform: capitalize better reflects the web behaviour Reviewed By: NickGerleman Differential Revision: D65023821 fbshipit-source-id: 8ba5fdbd7afb1460193bf82a2f4021c3aff2110a
- Loading branch information
1 parent
33e1ae1
commit dc2000c
Showing
5 changed files
with
98 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
packages/react-native/React/Tests/Text/RCTTextAttributesTest.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <XCTest/XCTest.h> | ||
|
||
#import <React/RCTTextAttributes.h> | ||
|
||
@interface RCTTextAttributesTest : XCTestCase | ||
|
||
@end | ||
|
||
@implementation RCTTextAttributesTest | ||
|
||
- (void)testCapitalize | ||
{ | ||
RCTTextAttributes *attrs = [RCTTextAttributes new]; | ||
attrs.textTransform = RCTTextTransformCapitalize; | ||
|
||
NSString *input = @"hello WORLD from ReAcT nAtIvE 2a !b c"; | ||
NSString *output = @"Hello WORLD From ReAcT NAtIvE 2a !B C"; | ||
XCTAssertEqualObjects([attrs applyTextAttributesToText:input], output); | ||
} | ||
|
||
- (void)testUppercase | ||
{ | ||
RCTTextAttributes *attrs = [RCTTextAttributes new]; | ||
attrs.textTransform = RCTTextTransformUppercase; | ||
|
||
NSString *input = @"hello WORLD from ReAcT nAtIvE 2a !b c"; | ||
NSString *output = @"HELLO WORLD FROM REACT NATIVE 2A !B C"; | ||
XCTAssertEqualObjects([attrs applyTextAttributesToText:input], output); | ||
} | ||
|
||
- (void)testLowercase | ||
{ | ||
RCTTextAttributes *attrs = [RCTTextAttributes new]; | ||
attrs.textTransform = RCTTextTransformLowercase; | ||
|
||
NSString *input = @"hello WORLD from ReAcT nAtIvE 2a !b c"; | ||
NSString *output = @"hello world from react native 2a !b c"; | ||
XCTAssertEqualObjects([attrs applyTextAttributesToText:input], output); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...eact-native/ReactAndroid/src/test/java/com/facebook/react/views/text/TextTransformTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.facebook.react.views.text | ||
|
||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.RobolectricTestRunner | ||
|
||
@RunWith(RobolectricTestRunner::class) | ||
class TextTransformTest { | ||
@Test | ||
fun textTransformCapitalize() { | ||
val input = "hello WORLD from ReAcT nAtIvE 2a !b c" | ||
val output = "Hello WORLD From ReAcT NAtIvE 2a !B C" | ||
assertThat(TextTransform.apply(input, TextTransform.CAPITALIZE)).isEqualTo(output) | ||
} | ||
|
||
@Test | ||
fun textTransformUppercase() { | ||
val input = "hello WORLD from ReAcT nAtIvE 2a !b c" | ||
val output = "HELLO WORLD FROM REACT NATIVE 2A !B C" | ||
assertThat(TextTransform.apply(input, TextTransform.UPPERCASE)).isEqualTo(output) | ||
} | ||
|
||
@Test | ||
fun textTransformLowercase() { | ||
val input = "hello WORLD from ReAcT nAtIvE 2a !b c" | ||
val output = "hello world from react native 2a !b c" | ||
assertThat(TextTransform.apply(input, TextTransform.LOWERCASE)).isEqualTo(output) | ||
} | ||
} |