1+ // Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
2+
3+ namespace FSharp.Compiler.UnitTests
4+
5+ open NUnit.Framework
6+ open FSharp.Compiler .SourceCodeServices
7+
8+ [<TestFixture>]
9+ module ` `List Tests`` =
10+
11+ [<Test>]
12+ let ``List hd should not exist`` () =
13+ // Regression test for FSharp1.0:5641
14+ // Title: List.hd/tl --> List.head/tail
15+
16+ CompilerAssert.TypeCheckSingleError
17+ """
18+ List.hd [1] |> ignore
19+ """
20+ FSharpErrorSeverity.Error
21+ 39
22+ ( 2 , 6 , 2 , 8 )
23+ " The value, constructor, namespace or type 'hd' is not defined."
24+
25+
26+
27+ [<Test>]
28+ let ``List tl should not exist`` () =
29+ // Regression test for FSharp1.0:5641
30+ // Title: List.hd/tl --> List.head/tail
31+
32+ CompilerAssert.TypeCheckSingleError
33+ """
34+ List.tl [1] |> ignore
35+ """
36+ FSharpErrorSeverity.Error
37+ 39
38+ ( 2 , 6 , 2 , 8 )
39+ " The value, constructor, namespace or type 'tl' is not defined."
40+
41+ [<Test>]
42+ let ``List head of empty list`` () =
43+ let testDelegate = TestDelegate ( fun _ -> ( List.head [] |> ignore))
44+
45+ Assert.Throws< System.ArgumentException> testDelegate |> ignore
46+
47+ [<Test>]
48+ let ``List tail of empty list`` () =
49+ let testDelegate = TestDelegate ( fun _ -> ( List.tail [] |> ignore))
50+
51+ Assert.Throws< System.ArgumentException> testDelegate |> ignore
52+
53+ [<Test>]
54+ let ``List head and tail`` () =
55+ Assert.areEqual 1 ( List.head [ 1 .. 10 ])
56+ Assert.areEqual " a" ( List.head [ " a" ])
57+ Assert.areEqual [ 2 .. 10 ] ( List.tail [ 1 .. 10 ])
58+ Assert.areEqual [] ( List.tail [ 1 ])
59+ Assert.areEqual ( List.head ( List.tail [ 'a' ; 'a' ])) ( List.head [ 'a' ; 'a' ])
0 commit comments