StringViewTests.mm 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import "Firestore/Source/Local/StringView.h"
  17. #import <XCTest/XCTest.h>
  18. #include <leveldb/slice.h>
  19. using Firestore::StringView;
  20. #define ASSERT_NSSTRING_TO_STRINGVIEW_AND_BACK_OK(nsstr) \
  21. StringView sv(nsstr); \
  22. leveldb::Slice slice = sv; \
  23. NSString *afterConversion = [[NSString alloc] initWithBytes:slice.data() \
  24. length:slice.size() \
  25. encoding:NSUTF8StringEncoding]; \
  26. XCTAssertEqualObjects(afterConversion, nsstr);
  27. @interface StringViewTests : XCTestCase
  28. @end
  29. @implementation StringViewTests
  30. - (void)testStringViewNSStringToSliceWithUSAscii {
  31. NSString *usAsciiChars = @"abcdefg ABCDEFG 12345 !@#$%";
  32. ASSERT_NSSTRING_TO_STRINGVIEW_AND_BACK_OK(usAsciiChars);
  33. }
  34. - (void)testStringViewNSStringToSliceWithNonUSAscii {
  35. NSString *nonUsAsciiChars = @"ó¹";
  36. ASSERT_NSSTRING_TO_STRINGVIEW_AND_BACK_OK(nonUsAsciiChars);
  37. }
  38. @end