@@ -2926,4 +2926,97 @@ TEST(TripleTest, isCompatibleWith) {
29262926 EXPECT_TRUE (DoTest (C.B , C.A , C.Result ));
29272927 }
29282928}
2929+
2930+ TEST (TripleTest, StrFirstN) {
2931+ // Empty triple
2932+ {
2933+ llvm::Triple triple;
2934+ ASSERT_EQ (triple.str (), " " );
2935+ ASSERT_EQ (triple.str (5 ), " " );
2936+ }
2937+
2938+ // Normal triple with 3 components
2939+ {
2940+ llvm::Triple triple (" arm64-apple-ios" );
2941+ ASSERT_EQ (triple.str (), " arm64-apple-ios" );
2942+ ASSERT_EQ (triple.str (5 ), " arm64-apple-ios" );
2943+ ASSERT_EQ (triple.str (4 ), " arm64-apple-ios" );
2944+ ASSERT_EQ (triple.str (3 ), " arm64-apple-ios" );
2945+ ASSERT_EQ (triple.str (2 ), " arm64-apple" );
2946+ ASSERT_EQ (triple.str (1 ), " arm64" );
2947+ ASSERT_EQ (triple.str (0 ), " " );
2948+ }
2949+
2950+ // Normal triple with 4 components
2951+ {
2952+ llvm::Triple triple (" arm64-apple-ios-simulator" );
2953+ ASSERT_EQ (triple.str (), " arm64-apple-ios-simulator" );
2954+ ASSERT_EQ (triple.str (5 ), " arm64-apple-ios-simulator" );
2955+ ASSERT_EQ (triple.str (4 ), " arm64-apple-ios-simulator" );
2956+ ASSERT_EQ (triple.str (3 ), " arm64-apple-ios" );
2957+ ASSERT_EQ (triple.str (2 ), " arm64-apple" );
2958+ ASSERT_EQ (triple.str (1 ), " arm64" );
2959+ ASSERT_EQ (triple.str (0 ), " " );
2960+ }
2961+
2962+ // Normal triple with 5 components
2963+ {
2964+ llvm::Triple triple (" arm64-apple-ios-simulator-macho" );
2965+ ASSERT_EQ (triple.str (), " arm64-apple-ios-simulator-macho" );
2966+ ASSERT_EQ (triple.str (5 ), " arm64-apple-ios-simulator-macho" );
2967+ ASSERT_EQ (triple.str (4 ), " arm64-apple-ios-simulator" );
2968+ ASSERT_EQ (triple.str (3 ), " arm64-apple-ios" );
2969+ ASSERT_EQ (triple.str (2 ), " arm64-apple" );
2970+ ASSERT_EQ (triple.str (1 ), " arm64" );
2971+ ASSERT_EQ (triple.str (0 ), " " );
2972+ }
2973+
2974+ // Empty vendor and os
2975+ {
2976+ llvm::Triple triple (" arm64---simulator-macho" );
2977+ ASSERT_EQ (triple.str (), " arm64---simulator-macho" );
2978+ ASSERT_EQ (triple.str (5 ), " arm64---simulator-macho" );
2979+ ASSERT_EQ (triple.str (4 ), " arm64---simulator" );
2980+ ASSERT_EQ (triple.str (3 ), " arm64--" );
2981+ ASSERT_EQ (triple.str (2 ), " arm64-" );
2982+ ASSERT_EQ (triple.str (1 ), " arm64" );
2983+ ASSERT_EQ (triple.str (0 ), " " );
2984+ }
2985+
2986+ // Empty environment
2987+ {
2988+ llvm::Triple triple (" arm64-apple-ios-" );
2989+ ASSERT_EQ (triple.str (), " arm64-apple-ios-" );
2990+ ASSERT_EQ (triple.str (5 ), " arm64-apple-ios-" );
2991+ ASSERT_EQ (triple.str (4 ), " arm64-apple-ios-" );
2992+ ASSERT_EQ (triple.str (3 ), " arm64-apple-ios" );
2993+ ASSERT_EQ (triple.str (2 ), " arm64-apple" );
2994+ ASSERT_EQ (triple.str (1 ), " arm64" );
2995+ ASSERT_EQ (triple.str (0 ), " " );
2996+ }
2997+
2998+ // Empty object format
2999+ {
3000+ llvm::Triple triple (" arm64-apple-ios-simulator-" );
3001+ ASSERT_EQ (triple.str (), " arm64-apple-ios-simulator-" );
3002+ ASSERT_EQ (triple.str (5 ), " arm64-apple-ios-simulator-" );
3003+ ASSERT_EQ (triple.str (4 ), " arm64-apple-ios-simulator" );
3004+ ASSERT_EQ (triple.str (3 ), " arm64-apple-ios" );
3005+ ASSERT_EQ (triple.str (2 ), " arm64-apple" );
3006+ ASSERT_EQ (triple.str (1 ), " arm64" );
3007+ ASSERT_EQ (triple.str (0 ), " " );
3008+ }
3009+
3010+ // Empty environment, but has object format
3011+ {
3012+ llvm::Triple triple (" arm64----macho" );
3013+ ASSERT_EQ (triple.str (), " arm64----macho" );
3014+ ASSERT_EQ (triple.str (5 ), " arm64----macho" );
3015+ ASSERT_EQ (triple.str (4 ), " arm64---" );
3016+ ASSERT_EQ (triple.str (3 ), " arm64--" );
3017+ ASSERT_EQ (triple.str (2 ), " arm64-" );
3018+ ASSERT_EQ (triple.str (1 ), " arm64" );
3019+ ASSERT_EQ (triple.str (0 ), " " );
3020+ }
3021+ }
29293022} // end anonymous namespace
0 commit comments