diff options
author | Mohamed Abdelnour <mohamed.k.abdelnour@gmail.com> | 2021-05-29 02:23:10 +0200 |
---|---|---|
committer | David Peter <sharkdp@users.noreply.github.com> | 2021-06-01 22:36:56 +0200 |
commit | d395f64f580c4c8f48d5c3b2e94d78ee9001c3ef (patch) | |
tree | 9c92397f3fd565dde9d5a07fbb85883d332c85ae /tests | |
parent | c9627040ccc74919af59a7602decf7797ef01085 (diff) |
Add F# syntax test file
Diffstat (limited to 'tests')
-rw-r--r-- | tests/syntax-tests/highlighted/F#/string.fs | 182 | ||||
-rw-r--r-- | tests/syntax-tests/source/F#/LICENSE.md | 27 | ||||
-rw-r--r-- | tests/syntax-tests/source/F#/string.fs | 182 |
3 files changed, 391 insertions, 0 deletions
diff --git a/tests/syntax-tests/highlighted/F#/string.fs b/tests/syntax-tests/highlighted/F#/string.fs new file mode 100644 index 00000000..338b5d60 --- /dev/null +++ b/tests/syntax-tests/highlighted/F#/string.fs @@ -0,0 +1,182 @@ +[38;2;117;113;94m// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.[0m + +[38;2;249;38;114mnamespace[0m[38;2;166;226;46m [0m[38;2;166;226;46mMicrosoft.FSharp.Core[0m + +[38;2;248;248;242m [0m[38;2;249;38;114mopen[0m[38;2;248;248;242m [0m[38;2;166;226;46mSystem[0m +[38;2;248;248;242m [0m[38;2;249;38;114mopen[0m[38;2;248;248;242m [0m[38;2;166;226;46mSystem[0m[38;2;166;226;46m.[0m[38;2;166;226;46mText[0m +[38;2;248;248;242m [0m[38;2;249;38;114mopen[0m[38;2;248;248;242m [0m[38;2;166;226;46mMicrosoft[0m[38;2;166;226;46m.[0m[38;2;166;226;46mFSharp[0m[38;2;166;226;46m.[0m[38;2;166;226;46mCore[0m[38;2;166;226;46m.[0m[38;2;166;226;46mLanguagePrimitives[0m[38;2;166;226;46m.[0m[38;2;166;226;46mIntrinsicOperators[0m +[38;2;248;248;242m [0m[38;2;249;38;114mopen[0m[38;2;248;248;242m [0m[38;2;166;226;46mMicrosoft[0m[38;2;166;226;46m.[0m[38;2;166;226;46mFSharp[0m[38;2;166;226;46m.[0m[38;2;166;226;46mCore[0m[38;2;166;226;46m.[0m[38;2;166;226;46mOperators[0m +[38;2;248;248;242m [0m[38;2;249;38;114mopen[0m[38;2;248;248;242m [0m[38;2;166;226;46mMicrosoft[0m[38;2;166;226;46m.[0m[38;2;166;226;46mFSharp[0m[38;2;166;226;46m.[0m[38;2;166;226;46mCore[0m[38;2;166;226;46m.[0m[38;2;166;226;46mOperators[0m[38;2;166;226;46m.[0m[38;2;166;226;46mChecked[0m +[38;2;248;248;242m [0m[38;2;249;38;114mopen[0m[38;2;248;248;242m [0m[38;2;166;226;46mMicrosoft[0m[38;2;166;226;46m.[0m[38;2;166;226;46mFSharp[0m[38;2;166;226;46m.[0m[38;2;166;226;46mCollections[0m +[38;2;248;248;242m [0m[38;2;249;38;114mopen[0m[38;2;248;248;242m [0m[38;2;166;226;46mMicrosoft[0m[38;2;166;226;46m.[0m[38;2;166;226;46mFSharp[0m[38;2;166;226;46m.[0m[38;2;166;226;46mPrimitives[0m[38;2;166;226;46m.[0m[38;2;166;226;46mBasics[0m + +[38;2;248;248;242m [0m[38;2;102;217;239m[<CompilationRepresentation[0m[38;2;249;38;114m([0m[38;2;102;217;239mCompilationRepresentationFlags.ModuleSuffix[0m[38;2;249;38;114m)[0m[38;2;102;217;239m>][0m +[38;2;248;248;242m [0m[38;2;102;217;239m[<RequireQualifiedAccess>][0m +[38;2;248;248;242m [0m[38;2;249;38;114mmodule[0m[38;2;166;226;46m [0m[38;2;166;226;46mString [0m[38;2;249;38;114m=[0m +[38;2;248;248;242m [0m[38;2;102;217;239m[<Literal>][0m +[38;2;248;248;242m [0m[38;2;117;113;94m/// LOH threshold is calculated from Internal.Utilities.Library.LOH_SIZE_THRESHOLD_BYTES,[0m +[38;2;248;248;242m [0m[38;2;117;113;94m/// and is equal to 80_000 / sizeof<char>[0m +[38;2;248;248;242m [0m[38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;248;248;242mLOH_CHAR_THRESHOLD[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m40_000[0m + +[38;2;248;248;242m [0m[38;2;102;217;239m[<CompiledName[0m[38;2;249;38;114m([0m[38;2;230;219;116m"[0m[38;2;230;219;116mLength[0m[38;2;230;219;116m"[0m[38;2;249;38;114m)[0m[38;2;102;217;239m>][0m +[38;2;248;248;242m [0m[38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;248;248;242mlength[0m[3;38;2;253;151;31m [0m[38;2;249;38;114m([0m[3;38;2;253;151;31mstr[0m[38;2;249;38;114m:[0m[38;2;166;226;46mstring[0m[38;2;249;38;114m)[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;249;38;114mif[0m[38;2;248;248;242m isNull str [0m[38;2;249;38;114mthen[0m[38;2;248;248;242m [0m[38;2;190;132;255m0[0m[38;2;248;248;242m [0m[38;2;249;38;114melse[0m[38;2;248;248;242m str.Length[0m + +[38;2;248;248;242m [0m[38;2;102;217;239m[<CompiledName[0m[38;2;249;38;114m([0m[38;2;230;219;116m"[0m[38;2;230;219;116mConcat[0m[38;2;230;219;116m"[0m[38;2;249;38;114m)[0m[38;2;102;217;239m>][0m +[38;2;248;248;242m [0m[38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;248;248;242mconcat[0m[3;38;2;253;151;31m sep [0m[38;2;249;38;114m([0m[3;38;2;253;151;31mstrings [0m[38;2;249;38;114m:[0m[38;2;248;248;242m [0m[38;2;166;226;46mseq[0m[38;2;249;38;114m<[0m[38;2;166;226;46mstring[0m[38;2;249;38;114m>[0m[38;2;249;38;114m)[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m + +[38;2;248;248;242m [0m[38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;248;248;242mconcatArray[0m[3;38;2;253;151;31m sep [0m[38;2;249;38;114m([0m[3;38;2;253;151;31mstrings[0m[38;2;249;38;114m:[0m[38;2;248;248;242m [0m[38;2;166;226;46mstring [0m[38;2;249;38;114m[[0m[38;2;249;38;114m][0m[38;2;249;38;114m)[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m +[38;2;248;248;242m [0m[38;2;249;38;114mmatch[0m[38;2;248;248;242m length sep [0m[38;2;249;38;114mwith[0m +[38;2;248;248;242m [0m[38;2;249;38;114m|[0m[38;2;248;248;242m [0m[38;2;190;132;255m0[0m[38;2;248;248;242m [0m[38;2;249;38;114m->[0m[38;2;248;248;242m String.Concat strings[0m +[38;2;248;248;242m [0m[38;2;117;113;94m// following line should be used when this overload becomes part of .NET Standard (it's only in .NET Core)[0m +[38;2;248;248;242m [0m[38;2;117;113;94m//| 1 -> String.Join(sep.[0], strings, 0, strings.Length)[0m +[38;2;248;248;242m [0m[38;2;249;38;114m|[0m[38;2;248;248;242m [0m[38;2;249;38;114m_[0m[38;2;248;248;242m [0m[38;2;249;38;114m->[0m[38;2;248;248;242m String.Join[0m[38;2;249;38;114m([0m[38;2;248;248;242msep[0m[38;2;249;38;114m,[0m[38;2;248;248;242m strings[0m[38;2;249;38;114m,[0m[38;2;248;248;242m [0m[38;2;190;132;255m0[0m[38;2;249;38;114m,[0m[38;2;248;248;242m strings.Length[0m[38;2;249;38;114m)[0m + +[38;2;248;248;242m [0m[38;2;249;38;114mmatch[0m[38;2;248;248;242m strings [0m[38;2;249;38;114mwith[0m +[38;2;248;248;242m [0m[38;2;249;38;114m|[0m[38;2;248;248;242m [0m[38;2;249;38;114m:[0m[38;2;248;248;242m? array[0m[38;2;249;38;114m<[0m[38;2;248;248;242mstring[0m[38;2;249;38;114m>[0m[38;2;248;248;242m [0m[38;2;249;38;114mas[0m[38;2;248;248;242m arr [0m[38;2;249;38;114m->[0m[38;2;248;248;242m [0m +[38;2;248;248;242m concatArray sep arr[0m + +[38;2;248;248;242m [0m[38;2;249;38;114m|[0m[38;2;248;248;242m [0m[38;2;249;38;114m:[0m[38;2;248;248;242m? list[0m[38;2;249;38;114m<[0m[38;2;248;248;242mstring[0m[38;2;249;38;114m>[0m[38;2;248;248;242m [0m[38;2;249;38;114mas[0m[38;2;248;248;242m lst [0m[38;2;249;38;114m->[0m[38;2;248;248;242m [0m +[38;2;248;248;242m lst [0m +[38;2;248;248;242m [0m[38;2;249;38;114m|>[0m[38;2;248;248;242m List.toArray [0m +[38;2;248;248;242m [0m[38;2;249;38;114m|>[0m[38;2;248;248;242m concatArray sep[0m + +[38;2;248;248;242m [0m[38;2;249;38;114m|[0m[38;2;248;248;242m [0m[38;2;249;38;114m_[0m[38;2;248;248;242m [0m[38;2;249;38;114m->[0m +[38;2;248;248;242m String.Join[0m[38;2;249;38;114m([0m[38;2;248;248;242msep[0m[38;2;249;38;114m,[0m[38;2;248;248;242m strings[0m[38;2;249;38;114m)[0m + +[38;2;248;248;242m [0m[38;2;102;217;239m[<CompiledName[0m[38;2;249;38;114m([0m[38;2;230;219;116m"[0m[38;2;230;219;116mIterate[0m[38;2;230;219;116m"[0m[38;2;249;38;114m)[0m[38;2;102;217;239m>][0m +[38;2;248;248;242m [0m[38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;248;248;242miter[0m[3;38;2;253;151;31m [0m[38;2;249;38;114m([0m[3;38;2;253;151;31maction [0m[38;2;249;38;114m:[0m[38;2;248;248;242m [0m[38;2;249;38;114m([0m[38;2;166;226;46mchar [0m[38;2;249;38;114m->[0m[38;2;166;226;46m unit[0m[38;2;249;38;114m)[0m[38;2;249;38;114m)[0m[38;2;248;248;242m [0m[38;2;249;38;114m([0m[3;38;2;253;151;31mstr[0m[38;2;249;38;114m:[0m[38;2;166;226;46mstring[0m[38;2;249;38;114m)[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m +[38;2;248;248;242m [0m[38;2;249;38;114mif[0m[38;2;248;248;242m [0m[38;2;249;38;114mnot[0m[38;2;248;248;242m [0m[38;2;249;38;114m([0m[38;2;248;248;242mString.IsNullOrEmpty str[0m[38;2;249;38;114m)[0m[38;2;248;248;242m [0m[38;2;249;38;114mthen[0m +[38;2;248;248;242m [0m[38;2;249;38;114mfor[0m[38;2;248;248;242m i [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m0[0m[38;2;248;248;242m [0m[38;2;249;38;114mto[0m[38;2;248;248;242m str.Length [0m[38;2;249;38;114m-[0m[38;2;248;248;242m [0m[38;2;190;132;255m1[0m[38;2;248;248;242m [0m[38;2;249;38;114mdo[0m +[38;2;248;248;242m action str.[0m[38;2;249;38;114m[[0m[38;2;248;248;242mi[0m[38;2;249;38;114m][0m[38;2;248;248;242m [0m + +[38;2;248;248;242m [0m[38;2;102;217;239m[<CompiledName[0m[38;2;249;38;114m([0m[38;2;230;219;116m"[0m[38;2;230;219;116mIterateIndexed[0m[38;2;230;219;116m"[0m[38;2;249;38;114m)[0m[38;2;102;217;239m>][0m +[38;2;248;248;242m [0m[38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;248;248;242miteri[0m[3;38;2;253;151;31m action [0m[38;2;249;38;114m([0m[3;38;2;253;151;31mstr[0m[38;2;249;38;114m:[0m[38;2;166;226;46mstring[0m[38;2;249;38;114m)[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m +[38;2;248;248;242m [0m[38;2;249;38;114mif[0m[38;2;248;248;242m [0m[38;2;249;38;114mnot[0m[38;2;248;248;242m [0m[38;2;249;38;114m([0m[38;2;248;248;242mString.IsNullOrEmpty str[0m[38;2;249;38;114m)[0m[38;2;248;248;242m [0m[38;2;249;38;114mthen[0m +[38;2;248;248;242m [0m[38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;248;248;242mf[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m OptimizedClosures.FSharpFunc[0m[38;2;249;38;114m<[0m[38;2;249;38;114m_[0m[38;2;249;38;114m,[0m[38;2;249;38;114m_[0m[38;2;249;38;114m,[0m[38;2;249;38;114m_[0m[38;2;249;38;114m>[0m[38;2;248;248;242m.Adapt[0m[38;2;249;38;114m([0m[38;2;248;248;242maction[0m[38;2;249;38;114m)[0m +[38;2;248;248;242m [0m[38;2;249;38;114mfor[0m[38;2;248;248;242m i [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m0[0m[38;2;248;248;242m [0m[38;2;249;38;114mto[0m[38;2;248;248;242m str.Length [0m[38;2;249;38;114m-[0m[38;2;248;248;242m [0m[38;2;190;132;255m1[0m[38;2;248;248;242m [0m[38;2;249;38;114mdo[0m +[38;2;248;248;242m f.Invoke[0m[38;2;249;38;114m([0m[38;2;248;248;242mi[0m[38;2;249;38;114m,[0m[38;2;248;248;242m str.[0m[38;2;249;38;114m[[0m[38;2;248;248;242mi[0m[38;2;249;38;114m][0m[38;2;249;38;114m)[0m[38;2;248;248;242m [0m + +[38;2;248;248;242m [0m[38;2;102;217;239m[<CompiledName[0m[38;2;249;38;114m([0m[38;2;230;219;116m"[0m[38;2;230;219;116mMap[0m[38;2;230;219;116m"[0m[38;2;249;38;114m)[0m[38;2;102;217;239m>][0m +[38;2;248;248;242m [0m[38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;248;248;242mmap[0m[3;38;2;253;151;31m [0m[38;2;249;38;114m([0m[3;38;2;253;151;31mmapping[0m[38;2;249;38;114m:[0m[38;2;248;248;242m [0m[38;2;166;226;46mchar [0m[38;2;249;38;114m->[0m[38;2;248;248;242m [0m[38;2;166;226;46mchar[0m[38;2;249;38;114m)[0m[38;2;248;248;242m [0m[38;2;249;38;114m([0m[3;38;2;253;151;31mstr[0m[38;2;249;38;114m:[0m[38;2;166;226;46mstring[0m[38;2;249;38;114m)[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m +[38;2;248;248;242m [0m[38;2;249;38;114mif[0m[38;2;248;248;242m String.IsNullOrEmpty str [0m[38;2;249;38;114mthen[0m +[38;2;248;248;242m String.Empty[0m +[38;2;248;248;242m [0m[38;2;249;38;114melse[0m +[38;2;248;248;242m [0m[38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;248;248;242mresult[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m str.ToCharArray[0m[38;2;190;132;255m()[0m +[38;2;248;248;242m [0m[38;2;249;38;114mlet mutable[0m[38;2;248;248;242m [0m[38;2;248;248;242mi[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m0[0m +[38;2;248;248;242m [0m[38;2;249;38;114mfor[0m[38;2;248;248;242m c [0m[38;2;249;38;114min[0m[38;2;248;248;242m result [0m[38;2;249;38;114mdo[0m +[38;2;248;248;242m result.[0m[38;2;249;38;114m[[0m[38;2;248;248;242mi[0m[38;2;249;38;114m][0m[38;2;248;248;242m [0m[38;2;249;38;114m<-[0m[38;2;248;248;242m mapping c[0m +[38;2;248;248;242m i [0m[38;2;249;38;114m<-[0m[38;2;248;248;242m i [0m[38;2;249;38;114m+[0m[38;2;248;248;242m [0m[38;2;190;132;255m1[0m + +[38;2;248;248;242m [0m[38;2;249;38;114mnew[0m[38;2;248;248;242m String[0m[38;2;249;38;114m([0m[38;2;248;248;242mresult[0m[38;2;249;38;114m)[0m + +[38;2;248;248;242m [0m[38;2;102;217;239m[<CompiledName[0m[38;2;249;38;114m([0m[38;2;230;219;116m"[0m[38;2;230;219;116mMapIndexed[0m[38;2;230;219;116m"[0m[38;2;249;38;114m)[0m[38;2;102;217;239m>][0m +[38;2;248;248;242m [0m[38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;248;248;242mmapi[0m[3;38;2;253;151;31m [0m[38;2;249;38;114m([0m[3;38;2;253;151;31mmapping[0m[38;2;249;38;114m:[0m[38;2;248;248;242m [0m[38;2;166;226;46mint [0m[38;2;249;38;114m->[0m[38;2;248;248;242m [0m[38;2;166;226;46mchar [0m[38;2;249;38;114m->[0m[38;2;248;248;242m [0m[38;2;166;226;46mchar[0m[38;2;249;38;114m)[0m[38;2;248;248;242m [0m[38;2;249;38;114m([0m[3;38;2;253;151;31mstr[0m[38;2;249;38;114m:[0m[38;2;166;226;46mstring[0m[38;2;249;38;114m)[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m +[38;2;248;248;242m [0m[38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;248;248;242mlen[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m length str[0m +[38;2;248;248;242m [0m[38;2;249;38;114mif[0m[38;2;248;248;242m len [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m0[0m[38;2;248;248;242m [0m[38;2;249;38;114mthen[0m[38;2;248;248;242m [0m +[38;2;248;248;242m String.Empty[0m +[38;2;248;248;242m [0m[38;2;249;38;114melse[0m +[38;2;248;248;242m [0m[38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;248;248;242mresult[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m str.ToCharArray[0m[38;2;190;132;255m()[0m +[38;2;248;248;242m [0m[38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;248;248;242mf[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m OptimizedClosures.FSharpFunc[0m[38;2;249;38;114m<[0m[38;2;249;38;114m_[0m[38;2;249;38;114m,[0m[38;2;249;38;114m_[0m[38;2;249;38;114m,[0m[38;2;249;38;114m_[0m[38;2;249;38;114m>[0m[38;2;248;248;242m.Adapt[0m[38;2;249;38;114m([0m[38;2;248;248;242mmapping[0m[38;2;249;38;114m)[0m + +[38;2;248;248;242m [0m[38;2;249;38;114mlet mutable[0m[38;2;248;248;242m [0m[38;2;248;248;242mi[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m0[0m +[38;2;248;248;242m [0m[38;2;249;38;114mwhile[0m[38;2;248;248;242m i [0m[38;2;249;38;114m<[0m[38;2;248;248;242m len [0m[38;2;249;38;114mdo[0m +[38;2;248;248;242m result.[0m[38;2;249;38;114m[[0m[38;2;248;248;242mi[0m[38;2;249;38;114m][0m[38;2;248;248;242m [0m[38;2;249;38;114m<-[0m[38;2;248;248;242m f.Invoke[0m[38;2;249;38;114m([0m[38;2;248;248;242mi[0m[38;2;249;38;114m,[0m[38;2;248;248;242m result.[0m[38;2;249;38;114m[[0m[38;2;248;248;242mi[0m[38;2;249;38;114m][0m[38;2;249;38;114m)[0m +[38;2;248;248;242m i [0m[38;2;249;38;114m<-[0m[38;2;248;248;242m i [0m[38;2;249;38;114m+[0m[38;2;248;248;242m [0m[38;2;190;132;255m1[0m + +[38;2;248;248;242m [0m[38;2;249;38;114mnew[0m[38;2;248;248;242m String[0m[38;2;249;38;114m([0m[38;2;248;248;242mresult[0m[38;2;249;38;114m)[0m + +[38;2;248;248;242m [0m[38;2;102;217;239m[<CompiledName[0m[38;2;249;38;114m([0m[38;2;230;219;116m"[0m[38;2;230;219;116mFilter[0m[38;2;230;219;116m"[0m[38;2;249;38;114m)[0m[38;2;102;217;239m>][0m +[38;2;248;248;242m [0m[38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;248;248;242mfilter[0m[3;38;2;253;151;31m [0m[38;2;249;38;114m([0m[3;38;2;253;151;31mpredicate[0m[38;2;249;38;114m:[0m[38;2;248;248;242m [0m[38;2;166;226;46mchar [0m[38;2;249;38;114m->[0m[38;2;248;248;242m [0m[38;2;166;226;46mbool[0m[38;2;249;38;114m)[0m[38;2;248;248;242m [0m[38;2;249;38;114m([0m[3;38;2;253;151;31mstr[0m[38;2;249;38;114m:[0m[38;2;166;226;46mstring[0m[38;2;249;38;114m)[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m +[38;2;248;248;242m [0m[38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;248;248;242mlen[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m length str[0m + +[38;2;248;248;242m [0m[38;2;249;38;114mif[0m[38;2;248;248;242m len [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m0[0m[38;2;248;248;242m [0m[38;2;249;38;114mthen[0m[38;2;248;248;242m [0m +[38;2;248;248;242m String.Empty[0m + +[38;2;248;248;242m [0m[38;2;249;38;114melif[0m[38;2;248;248;242m len [0m[38;2;249;38;114m>[0m[38;2;248;248;242m LOH[0m[38;2;249;38;114m_[0m[38;2;248;248;242mCHAR[0m[38;2;249;38;114m_[0m[38;2;248;248;242mTHRESHOLD [0m[38;2;249;38;114mthen[0m +[38;2;248;248;242m [0m[38;2;117;113;94m// By using SB here, which is twice slower than the optimized path, we prevent LOH allocations [0m +[38;2;248;248;242m [0m[38;2;117;113;94m// and 'stop the world' collections if the filtering results in smaller strings.[0m +[38;2;248;248;242m [0m[38;2;117;113;94m// We also don't pre-allocate SB here, to allow for less mem pressure when filter result is small.[0m +[38;2;248;248;242m [0m[38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;248;248;242mres[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m StringBuilder[0m[38;2;190;132;255m()[0m +[38;2;248;248;242m str [0m[38;2;249;38;114m|>[0m[38;2;248;248;242m iter [0m[38;2;249;38;114m([0m[38;2;249;38;114mfun[0m[3;38;2;253;151;31m c [0m[38;2;249;38;114m->[0m[38;2;248;248;242m [0m[38;2;249;38;114mif[0m[38;2;248;248;242m predicate c [0m[38;2;249;38;114mthen[0m[38;2;248;248;242m res.Append c [0m[38;2;249;38;114m|>[0m[38;2;248;248;242m ignore[0m[38;2;249;38;114m)[0m +[38;2;248;248;242m res.ToString[0m[38;2;190;132;255m()[0m + +[38;2;248;248;242m [0m[38;2;249;38;114melse[0m +[38;2;248;248;242m [0m[38;2;117;113;94m// Must do it this way, since array.fs is not yet in scope, but this is safe[0m +[38;2;248;248;242m [0m[38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;248;248;242mtarget[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked len[0m +[38;2;248;248;242m [0m[38;2;249;38;114mlet mutable[0m[38;2;248;248;242m [0m[38;2;248;248;242mi[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m0[0m +[38;2;248;248;242m [0m[38;2;249;38;114mfor[0m[38;2;248;248;242m c [0m[38;2;249;38;114min[0m[38;2;248;248;242m str [0m[38;2;249;38;114mdo[0m +[38;2;248;248;242m [0m[38;2;249;38;114mif[0m[38;2;248;248;242m predicate c [0m[38;2;249;38;114mthen[0m[38;2;248;248;242m [0m +[38;2;248;248;242m target.[0m[38;2;249;38;114m[[0m[38;2;248;248;242mi[0m[38;2;249;38;114m][0m[38;2;248;248;242m [0m[38;2;249;38;114m<-[0m[38;2;248;248;242m c[0m +[38;2;248;248;242m i [0m[38;2;249;38;114m<-[0m[38;2;248;248;242m i [0m[38;2;249;38;114m+[0m[38;2;248;248;242m [0m[38;2;190;132;255m1[0m + +[38;2;248;248;242m String[0m[38;2;249;38;114m([0m[38;2;248;248;242mtarget[0m[38;2;249;38;114m,[0m[38;2;248;248;242m [0m[38;2;190;132;255m0[0m[38;2;249;38;114m,[0m[38;2;248;248;242m i[0m[38;2;249;38;114m)[0m + +[38;2;248;248;242m [0m[38;2;102;217;239m[<CompiledName[0m[38;2;249;38;114m([0m[38;2;230;219;116m"[0m[38;2;230;219;116mCollect[0m[38;2;230;219;116m"[0m[38;2;249;38;114m)[0m[38;2;102;217;239m>][0m +[38;2;248;248;242m [0m[38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;248;248;242mcollect[0m[3;38;2;253;151;31m [0m[38;2;249;38;114m([0m[3;38;2;253;151;31mmapping[0m[38;2;249;38;114m:[0m[38;2;248;248;242m [0m[38;2;166;226;46mchar [0m[38;2;249;38;114m->[0m[38;2;248;248;242m [0m[38;2;166;226;46mstring[0m[38;2;249;38;114m)[0m[38;2;248;248;242m [0m[38;2;249;38;114m([0m[3;38;2;253;151;31mstr[0m[38;2;249;38;114m:[0m[38;2;166;226;46mstring[0m[38;2;249;38;114m)[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m +[38;2;248;248;242m [0m[38;2;249;38;114mif[0m[38;2;248;248;242m String.IsNullOrEmpty str [0m[38;2;249;38;114mthen[0m +[38;2;248;248;242m String.Empty[0m +[38;2;248;248;242m [0m[38;2;249;38;114melse[0m +[38;2;248;248;242m [0m[38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;248;248;242mres[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m StringBuilder str.Length[0m +[38;2;248;248;242m str [0m[38;2;249;38;114m|>[0m[38;2;248;248;242m iter [0m[38;2;249;38;114m([0m[38;2;249;38;114mfun[0m[3;38;2;253;151;31m c [0m[38;2;249;38;114m->[0m[38;2;248;248;242m res.Append[0m[38;2;249;38;114m([0m[38;2;248;248;242mmapping c[0m[38;2;249;38;114m)[0m[38;2;248;248;242m [0m[38;2;249;38;114m|>[0m[38;2;248;248;242m ignore[0m[38;2;249;38;114m)[0m +[38;2;248;248;242m res.ToString[0m[38;2;190;132;255m()[0m + +[38;2;248;248;242m [0m[38;2;102;217;239m[<CompiledName[0m[38;2;249;38;114m([0m[38;2;230;219;116m"[0m[38;2;230;219;116mInitialize[0m[38;2;230;219;116m"[0m[38;2;249;38;114m)[0m[38;2;102;217;239m>][0m +[38;2;248;248;242m [0m[38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;248;248;242minit[0m[3;38;2;253;151;31m [0m[38;2;249;38;114m([0m[3;38;2;253;151;31mcount[0m[38;2;249;38;114m:[0m[38;2;166;226;46mint[0m[38;2;249;38;114m)[0m[38;2;248;248;242m [0m[38;2;249;38;114m([0m[3;38;2;253;151;31minitializer[0m[38;2;249;38;114m:[0m[38;2;248;248;242m [0m[38;2;166;226;46mint[0m[38;2;249;38;114m->[0m[38;2;248;248;242m [0m[38;2;166;226;46mstring[0m[38;2;249;38;114m)[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m +[38;2;248;248;242m [0m[38;2;249;38;114mif[0m[38;2;248;248;242m count [0m[38;2;249;38;114m<[0m[38;2;248;248;242m [0m[38;2;190;132;255m0[0m[38;2;248;248;242m [0m[38;2;249;38;114mthen[0m[38;2;248;248;242m invalidArgInputMustBeNonNegative [0m[38;2;230;219;116m"[0m[38;2;230;219;116mcount[0m[38;2;230;219;116m"[0m[38;2;248;248;242m count[0m +[38;2;248;248;242m [0m[38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;248;248;242mres[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m StringBuilder count[0m +[38;2;248;248;242m [0m[38;2;249;38;114mfor[0m[38;2;248;248;242m i [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m0[0m[38;2;248;248;242m [0m[38;2;249;38;114mto[0m[38;2;248;248;242m count [0m[38;2;249;38;114m-[0m[38;2;248;248;242m [0m[38;2;190;132;255m1[0m[38;2;248;248;242m [0m[38;2;249;38;114mdo[0m[38;2;248;248;242m [0m +[38;2;248;248;242m res.Append[0m[38;2;249;38;114m([0m[38;2;248;248;242minitializer i[0m[38;2;249;38;114m)[0m[38;2;248;248;242m [0m[38;2;249;38;114m|>[0m[38;2;248;248;242m ignore[0m +[38;2;248;248;242m res.ToString[0m[38;2;190;132;255m()[0m + +[38;2;248;248;242m [0m[38;2;102;217;239m[<CompiledName[0m[38;2;249;38;114m([0m[38;2;230;219;116m"[0m[38;2;230;219;116mReplicate[0m[38;2;230;219;116m"[0m[38;2;249;38;114m)[0m[38;2;102;217;239m>][0m +[38;2;248;248;242m [0m[38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;248;248;242mreplicate[0m[3;38;2;253;151;31m [0m[38;2;249;38;114m([0m[3;38;2;253;151;31mcount[0m[38;2;249;38;114m:[0m[38;2;166;226;46mint[0m[38;2;249;38;114m)[0m[38;2;248;248;242m [0m[38;2;249;38;114m([0m[3;38;2;253;151;31mstr[0m[38;2;249;38;114m:[0m[38;2;166;226;46mstring[0m[38;2;249;38;114m)[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m +[38;2;248;248;242m [0m[38;2;249;38;114mif[0m[38;2;248;248;242m count [0m[38;2;249;38;114m<[0m[38;2;248;248;242m [0m[38;2;190;132;255m0[0m[38;2;248;248;242m [0m[38;2;249;38;114mthen[0m[38;2;248;248;242m invalidArgInputMustBeNonNegative [0m[38;2;230;219;116m"[0m[38;2;230;219;116mcount[0m[38;2;230;219;116m"[0m[38;2;248;248;242m count[0m + +[38;2;248;248;242m [0m[38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;248;248;242mlen[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m length str[0m +[38;2;248;248;242m [0m[38;2;249;38;114mif[0m[38;2;248;248;242m len [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m0[0m[38;2;248;248;242m [0m[38;2;249;38;114m||[0m[38;2;248;248;242m count [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m0[0m[38;2;248;248;242m [0m[38;2;249;38;114mthen[0m[38;2;248;248;242m [0m +[38;2;248;248;242m String.Empty[0m + +[38;2;248;248;242m [0m[38;2;249;38;114melif[0m[38;2;248;248;242m len [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m1[0m[38;2;248;248;242m [0m[38;2;249;38;114mthen[0m +[38;2;248;248;242m [0m[38;2;249;38;114mnew[0m[38;2;248;248;242m String[0m[38;2;249;38;114m([0m[38;2;248;248;242mstr.[0m[38;2;249;38;114m[[0m[38;2;190;132;255m0[0m[38;2;249;38;114m][0m[38;2;249;38;114m,[0m[38;2;248;248;242m count[0m[38;2;249;38;114m)[0m + +[38;2;248;248;242m [0m[38;2;249;38;114melif[0m[38;2;248;248;242m count [0m[38;2;249;38;114m<[0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;190;132;255m4[0m[38;2;248;248;242m [0m[38;2;249;38;114mthen[0m +[38;2;248;248;242m [0m[38;2;249;38;114mmatch[0m[38;2;248;248;242m count [0m[38;2;249;38;114mwith[0m +[38;2;248;248;242m [0m[38;2;249;38;114m|[0m[38;2;248;248;242m [0m[38;2;190;132;255m1[0m[38;2;248;248;242m [0m[38;2;249;38;114m->[0m[38;2;248;248;242m str[0m +[38;2;248;248;242m [0m[38;2;249;38;114m|[0m[38;2;248;248;242m [0m[38;2;190;132;255m2[0m[38;2;248;248;242m [0m[38;2;249;38;114m->[0m[38;2;248;248;242m String.Concat[0m[38;2;249;38;114m([0m[38;2;248;248;242mstr[0m[38;2;249;38;114m,[0m[38;2;248;248;242m str[0m[38;2;249;38;114m)[0m +[38;2;248;248;242m [0m[38;2;249;38;114m|[0m[38;2;248;248;242m [0m[38;2;190;132;255m3[0m[38;2;248;248;242m [0m[38;2;249;38;114m->[0m[38;2;248;248;242m String.Concat[0m[38;2;249;38;114m([0m[38;2;248;248;242mstr[0m[38;2;249;38;114m,[0m[38;2;248;248;242m str[0m[38;2;249;38;114m,[0m[38;2;248;248;242m str[0m[38;2;249;38;114m)[0m +[38;2;248;248;242m [0m[38;2;249;38;114m|[0m[38;2;248;248;242m [0m[38;2;249;38;114m_[0m[38;2;248;248;242m [0m[38;2;249;38;114m->[0m[38;2;248;248;242m String.Concat[0m[38;2;249;38;114m([0m[38;2;248;248;242mstr[0m[38;2;249;38;114m,[0m[38;2;248;248;242m str[0m[38;2;249;38;114m,[0m[38;2;248;248;242m str[0m[38;2;249;38;114m,[0m[38;2;248;248;242m str[0m[38;2;249;38;114m)[0m + +[38;2;248;248;242m [0m[38;2;249;38;114melse[0m +[38;2;248;248;242m [0m[38;2;117;113;94m// Using the primitive, because array.fs is not yet in scope. It's safe: both len and count are positive.[0m +[38;2;248;248;242m [0m[38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;248;248;242mtarget[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked [0m[38;2;249;38;114m([0m[38;2;248;248;242mlen [0m[38;2;249;38;114m*[0m[38;2;248;248;242m count[0m[38;2;249;38;114m)[0m +[38;2;248;248;242m [0m[38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;248;248;242msource[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m str.ToCharArray[0m[38;2;190;132;255m()[0m + +[38;2;248;248;242m [0m[38;2;117;113;94m// O(log(n)) performance loop:[0m +[38;2;248;248;242m [0m[38;2;117;113;94m// Copy first string, then keep copying what we already copied [0m +[38;2;248;248;242m [0m[38;2;117;113;94m// (i.e., doubling it) until we reach or pass the halfway point[0m +[38;2;248;248;242m Array.Copy[0m[38;2;249;38;114m([0m[38;2;248;248;242msource[0m[38;2;249;38;114m,[0m[38;2;248;248;242m [0m[38;2;190;132;255m0[0m[38;2;249;38;114m,[0m[38;2;248;248;242m target[0m[38;2;249;38;114m,[0m[38;2;248;248;242m [0m[38;2;190;132;255m0[0m[38;2;249;38;114m,[0m[38;2;248;248;242m len[0m[38;2;249;38;114m)[0m +[38;2;248;248;242m [0m[38;2;249;38;114mlet mutable[0m[38;2;248;248;242m [0m[38;2;248;248;242mi[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m[38;2;248;248;242m len[0m +[38;2;248;248;242m [0m[38;2;249;38;114mwhile[0m[38;2;248;248;242m i [0m[38;2;249;38;114m*[0m[38;2;248;248;242m [0m[38;2;190;132;255m2[0m[38;2;248;248;242m [0m[38;2;249;38;114m<[0m[38;2;248;248;242m target.Length [0m[38;2;249;38;114mdo[0m +[38;2;248;248;242m Array.Copy[0m[38;2;249;38;114m([0m[38;2;248;248;242mtarget[0m[38;2;249;38;114m,[0m[38;2;248;248;242m [0m[38;2;190;132;255m0[0m[38;2;249;38;114m,[0m[38;2;248;248;242m target[0m[38;2;249;38;114m,[0m[38;2;248;248;242m i[0m[38;2;249;38;114m,[0m[38;2;248;248;242m i[0m[38;2;249;38;114m)[0m +[38;2;248;248;242m i [0m[38;2;249;38;114m<-[0m[38;2;248;248;242m i [0m[38;2;249;38;114m*[0m[38;2;248;248;242m [0m[38;2;190;132;255m2[0m + +[38;2;248;248;242m [0m[38;2;117;113;94m// finally, copy the remain half, or less-then half[0m +[38;2;248;248;242m Array.Copy[0m[38;2;249;38;114m([0m[38;2;248;248;242mtarget[0m[38;2;249;38;114m,[0m[38;2;248;248;242m [0m[38;2;190;132;255m0[0m[38;2;249;38;114m,[0m[38;2;248;248;242m target[0m[38;2;249;38;114m,[0m[38;2;248;248;242m i[0m[38;2;249;38;114m,[0m[38;2;248;248;242m target.Length [0m[38;2;249;38;114m-[0m[38;2;248;248;242m i[0m[38;2;249;38;114m)[0m +[38;2;248;248;242m [0m[38;2;249;38;114mnew[0m[38;2;248;248;242m String[0m[38;2;249;38;114m([0m[38;2;248;248;242mtarget[0m[38;2;249;38;114m)[0m + + +[38;2;248;248;242m [0m[38;2;102;217;239m[<CompiledName[0m[38;2;249;38;114m([0m[38;2;230;219;116m"[0m[38;2;230;219;116mForAll[0m[38;2;230;219;116m"[0m[38;2;249;38;114m)[0m[38;2;102;217;239m>][0m +[38;2;248;248;242m [0m[38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;248;248;242mforall[0m[3;38;2;253;151;31m predicate [0m[38;2;249;38;114m([0m[3;38;2;253;151;31mstr[0m[38;2;249;38;114m:[0m[38;2;166;226;46mstring[0m[38;2;249;38;114m)[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m +[38;2;248;248;242m [0m[38;2;249;38;114mif[0m[38;2;248;248;242m String.IsNullOrEmpty str [0m[38;2;249;38;114mthen[0m +[38;2;248;248;242m [0m[38;2;190;132;255mtrue[0m +[38;2;248;248;242m [0m[38;2;249;38;114melse[0m +[38;2;248;248;242m [0m[38;2;249;38;114mlet[0m[38;2;249;38;114m rec[0m[38;2;248;248;242m [0m[38;2;248;248;242mcheck[0m[3;38;2;253;151;31m i [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;249;38;114m([0m[38;2;248;248;242mi [0m[38;2;249;38;114m>[0m[38;2;249;38;114m=[0m[38;2;248;248;242m str.Length[0m[38;2;249;38;114m)[0m[38;2;248;248;242m [0m[38;2;249;38;114m||[0m[38;2;248;248;242m [0m[38;2;249;38;114m([0m[38;2;248;248;242mpredicate str.[0m[38;2;249;38;114m[[0m[38;2;248;248;242mi[0m[38;2;249;38;114m][0m[38;2;248;248;242m [0m[38;2;249;38;114m&&[0m[38;2;248;248;242m check [0m[38;2;249;38;114m([0m[38;2;248;248;242mi[0m[38;2;249;38;114m+[0m[38;2;190;132;255m1[0m[38;2;249;38;114m)[0m[38;2;249;38;114m)[0m[38;2;248;248;242m [0m +[38;2;248;248;242m check [0m[38;2;190;132;255m0[0m + +[38;2;248;248;242m [0m[38;2;102;217;239m[<CompiledName[0m[38;2;249;38;114m([0m[38;2;230;219;116m"[0m[38;2;230;219;116mExists[0m[38;2;230;219;116m"[0m[38;2;249;38;114m)[0m[38;2;102;217;239m>][0m +[38;2;248;248;242m [0m[38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;248;248;242mexists[0m[3;38;2;253;151;31m predicate [0m[38;2;249;38;114m([0m[3;38;2;253;151;31mstr[0m[38;2;249;38;114m:[0m[38;2;166;226;46mstring[0m[38;2;249;38;114m)[0m[38;2;248;248;242m [0m[38;2;249;38;114m=[0m +[38;2;248;248;242m [0m[38;2;249;38;114mif[0m[38;2;248;248;242m String.IsNullOrEmpty str [0m[38;2;249;38;114mthen[0m +[38;2;248;248;242m [0m[38;2;190;132;255mfalse[0m +[38;2;248;248;242m [0m[38;2;249;38;114melse[0m +[38;2;248;248;242m [0m[38;2;249;38;114mlet[0m[38;2;249;38;114m rec[0m[38;2;248;248;242m [0m[38;2;248;248;242mcheck[0m[3;38;2;253;151;31m i [0m[38;2;249;38;114m=[0m[38;2;248;248;242m [0m[38;2;249;38;114m([0m[38;2;248;248;242mi [0m[38;2;249;38;114m<[0m[38;2;248;248;242m str.Length[0m[38;2;249;38;114m)[0m[38;2;248;248;242m [0m[38;2;249;38;114m&&[0m[38;2;248;248;242m [0m[38;2;249;38;114m([0m[38;2;248;248;242mpredicate str.[0m[38;2;249;38;114m[[0m[38;2;248;248;242mi[0m[38;2;249;38;114m][0m[38;2;248;248;242m [0m[38;2;249;38;114m||[0m[38;2;248;248;242m check [0m[38;2;249;38;114m([0m[38;2;248;248;242mi[0m[38;2;249;38;114m+[0m[38;2;190;132;255m1[0m[38;2;249;38;114m)[0m[38;2;249;38;114m)[0m[38;2;248;248;242m [0m +[38;2;248;248;242m check [0m[38;2;190;132;255m0[0m[38;2;248;248;242m [0m diff --git a/tests/syntax-tests/source/F#/LICENSE.md b/tests/syntax-tests/source/F#/LICENSE.md new file mode 100644 index 00000000..7473c821 --- /dev/null +++ b/tests/syntax-tests/source/F#/LICENSE.md @@ -0,0 +1,27 @@ +The `string.fs` file has been added from https://github.com/dotnet/fsharp under the following license: + +```text +The MIT License (MIT) + +Copyright (c) Microsoft Corporation. +All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +``` diff --git a/tests/syntax-tests/source/F#/string.fs b/tests/syntax-tests/source/F#/string.fs new file mode 100644 index 00000000..37e8fcd7 --- /dev/null +++ b/tests/syntax-tests/source/F#/string.fs @@ -0,0 +1,182 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +namespace Microsoft.FSharp.Core + + open System + open System.Text + open Microsoft.FSharp.Core.LanguagePrimitives.IntrinsicOperators + open Microsoft.FSharp.Core.Operators + open Microsoft.FSharp.Core.Operators.Checked + open Microsoft.FSharp.Collections + open Microsoft.FSharp.Primitives.Basics + + [<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>] + [<RequireQualifiedAccess>] + module String = + [<Literal>] + /// LOH threshold is calculated from Internal.Utilities.Library.LOH_SIZE_THRESHOLD_BYTES, + /// and is equal to 80_000 / sizeof<char> + let LOH_CHAR_THRESHOLD = 40_000 + + [<CompiledName("Length")>] + let length (str:string) = if isNull str then 0 else str.Length + + [<CompiledName("Concat")>] + let concat sep (strings : seq<string>) = + + let concatArray sep (strings: string []) = + match length sep with + | 0 -> String.Concat strings + // following line should be used when this overload becomes part of .NET Standard (it's only in .NET Core) + //| 1 -> String.Join(sep.[0], strings, 0, strings.Length) + | _ -> String.Join(sep, strings, 0, strings.Length) + + match strings with + | :? array<string> as arr -> + concatArray sep arr + + | :? list<string> as lst -> + lst + |> List.toArray + |> concatArray sep + + | _ -> + String.Join(sep, strings) + + [<CompiledName("Iterate")>] + let iter (action : (char -> unit)) (str:string) = + if not (String.IsNullOrEmpty str) then + for i = 0 to str.Length - 1 do + action str.[i] + + [<CompiledName("IterateIndexed")>] + let iteri action (str:string) = + if not (String.IsNullOrEmpty str) then + let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(action) + for i = 0 to str.Length - 1 do + f.Invoke(i, str.[i]) + + [<CompiledName("Map")>] + let map (mapping: char -> char) (str:string) = + if String.IsNullOrEmpty str then + String.Empty + else + let result = str.ToCharArray() + let mutable i = 0 + for c in result do + result.[i] <- mapping c + i <- i + 1 + + new String(result) + + [<CompiledName("MapIndexed")>] + let mapi (mapping: int -> char -> char) (str:string) = + let len = length str + if len = 0 then + String.Empty + else + let result = str.ToCharArray() + let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(mapping) + + let mutable i = 0 + while i < len do + result.[i] <- f.Invoke(i, result.[i]) + i <- i + 1 + + new String(result) + + [<CompiledName("Filter")>] + let filter (predicate: char -> bool) (str:string) = + let len = length str + + if len = 0 then + String.Empty + + elif len > LOH_CHAR_THRESHOLD then + // By using SB here, which is twice slower than the optimized path, we prevent LOH allocations + // and 'stop the world' collections if the filtering results in smaller strings. + // We also don't pre-allocate SB here, to allow for less mem pressure when filter result is small. + let res = StringBuilder() + str |> iter (fun c -> if predicate c then res.Append c |> ignore) + res.ToString() + + else + // Must do it this way, since array.fs is not yet in scope, but this is safe + let target = Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked len + let mutable i = 0 + for c in str do + if predicate c then + target.[i] <- c + i <- i + 1 + + String(target, 0, i) + + [<CompiledName("Collect")>] + let collect (mapping: char -> string) (str:string) = + if String.IsNullOrEmpty str then + String.Empty + else + let res = StringBuilder str.Length + str |> iter (fun c -> res.Append(mapping c) |> ignore) + res.ToString() + + [<CompiledName("Initialize")>] + let init (count:int) (initializer: int-> string) = + if count < 0 then invalidArgInputMustBeNonNegative "count" count + let res = StringBuilder count + for i = 0 to count - 1 do + res.Append(initializer i) |> ignore + res.ToString() + + [<CompiledName("Replicate")>] + let replicate (count:int) (str:string) = + if count < 0 then invalidArgInputMustBeNonNegative "count" count + + let len = length str + if len = 0 || count = 0 then + String.Empty + + elif len = 1 then + new String(str.[0], count) + + elif count <= 4 then + match count with + | 1 -> str + | 2 -> String.Concat(str, str) + | 3 -> String.Concat(str, str, str) + | _ -> String.Concat(str, str, str, str) + + else + // Using the primitive, because array.fs is not yet in scope. It's safe: both len and count are positive. + let target = Microsoft.FSharp.Primitives.Basics.Array.zeroCreateUnchecked (len * count) + let source = str.ToCharArray() + + // O(log(n)) performance loop: + // Copy first string, then keep copying what we already copied + // (i.e., doubling it) until we reach or pass the halfway point + Array.Copy(source, 0, target, 0, len) + let mutable i = len + while i * 2 < target.Length do + Array.Copy(target, 0, target, i, i) + i <- i * 2 + + // finally, copy the remain half, or less-then half + Array.Copy(target, 0, target, i, target.Length - i) + new String(target) + + + [<CompiledName("ForAll")>] + let forall predicate (str:string) = + if String.IsNullOrEmpty str then + true + else + let rec check i = (i >= str.Length) || (predicate str.[i] && check (i+1)) + check 0 + + [<CompiledName("Exists")>] + let exists predicate (str:string) = + if String.IsNullOrEmpty str then + false + else + let rec check i = (i < str.Length) && (predicate str.[i] || check (i+1)) + check 0 |