Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAngryByrd committed May 9, 2024
1 parent e876ee7 commit 6df1ab7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 37 deletions.
75 changes: 39 additions & 36 deletions tests/GenerateTests.fs
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
namespace Ionide.LanguageServerProtocol



module String =
open System

let toPascalCase (s: string) =
s.[0]
|> Char.ToUpper
|> fun c -> c.ToString() + s.Substring(1)
|> fun c ->
c.ToString()
+ s.Substring(1)

module Array =
/// <summary>Places separator between each element of items</summary>
let intersperse (separator: 'a) (items: 'a array) : 'a array = [|
let mutable notFirst = false

for element in items do
if notFirst then
yield separator

yield element
notFirst <- true
|]

module rec MetaModel =
open System
Expand Down Expand Up @@ -136,8 +150,7 @@ module rec MetaModel =
x.Optional
|> Option.defaultValue false

member x.NameAsPascalCase =
String.toPascalCase x.Name
member x.NameAsPascalCase = String.toPascalCase x.Name

[<Literal>]
let StructureTypeLiteral = "literal"
Expand Down Expand Up @@ -201,17 +214,14 @@ module rec MetaModel =
Since: string option
Type: Type
}
[<JsonConverter(typeof<StringEnumConverter>)>]

[<JsonConverter(typeof<Newtonsoft.Json.Converters.StringEnumConverter>)>]
type EnumerationTypeNameValues =
| String = 0
| Integer = 1
| Uinteger = 2
| String = 0
| Integer = 1
| Uinteger = 2

type EnumerationType = {
Kind : string
Name : EnumerationTypeNameValues
}
type EnumerationType = { Kind: string; Name: EnumerationTypeNameValues }

type EnumerationEntry = {
Deprecated: string option
Expand All @@ -228,8 +238,8 @@ module rec MetaModel =
Name: string
Proposed: bool option
Since: string option
SupportsCustomValues : bool option
Type : EnumerationType
SupportsCustomValues: bool option
Type: EnumerationType
Values: EnumerationEntry array
}

Expand Down Expand Up @@ -365,19 +375,12 @@ module GenerateTests =
types
|> Array.map (Choice1Of2)

let asterisk = SingleTextNode("*", rangeZero)

let types =
types
|> Array.collect (fun x ->
[|
x
Choice2Of2(SingleTextNode("*", rangeZero))
|]

)
let types =
types
|> Array.removeAt (types.Length - 1)
|> List.ofArray
|> Array.intersperse (Choice2Of2(asterisk))
|> Array.toList

TypeTupleNode(types, rangeZero)
|> Type.Tuple
Expand Down Expand Up @@ -411,7 +414,7 @@ module GenerateTests =
| MetaModel.Type.BaseType b ->
let name = b.Name.ToDotNetType()
Type.FromString name

| MetaModel.Type.OrType o ->

// TS types can have optional properties (myKey?: string)
Expand Down Expand Up @@ -556,8 +559,9 @@ module GenerateTests =
&& isEmptyProperties

let createStructure (structure: MetaModel.Structure) (model: MetaModel.MetaModel) =

let alreadyAddedKey = ResizeArray<string>()

let rec expandFields (structure: MetaModel.Structure) = [
let structure = createSafeStructure structure

Expand Down Expand Up @@ -608,7 +612,8 @@ module GenerateTests =

let createTypeAlias (alias: MetaModel.TypeAlias) =
let rec getType (t: MetaModel.Type) =
if alias.Name = "LSPAny" then Type.FromString "obj"
if alias.Name = "LSPAny" then
Type.FromString "obj"
else
match t with
| MetaModel.Type.ReferenceType r -> Type.FromString r.Name
Expand Down Expand Up @@ -675,11 +680,14 @@ module GenerateTests =
match enumeration.Type.Name with
| MetaModel.EnumerationTypeNameValues.String ->
Enum enumeration.Name {
for i,v in enumeration.Values |> Array.mapi(fun i x -> i,x) do
for i, v in
enumeration.Values
|> Array.mapi (fun i x -> i, x) do
// if v.Name.ToLower() <> v.Value.ToLower() then failwithf "Unknown string literal enum combo %A %A" v.Name v.Value
EnumCase(String.toPascalCase v.Name, string i)
}
| MetaModel.EnumerationTypeNameValues.Integer | MetaModel.EnumerationTypeNameValues.Uinteger ->
| MetaModel.EnumerationTypeNameValues.Integer
| MetaModel.EnumerationTypeNameValues.Uinteger ->
Enum enumeration.Name {
for v in enumeration.Values do
EnumCase(String.toPascalCase v.Name, v.Value)
Expand Down Expand Up @@ -774,23 +782,18 @@ module GenerateTests =
for i in [ 2..5 ] do
EscapeHatch(createErasedUnionType i)


for s in parsedMetaModel.Structures do
if isUnitStructure s then
Abbrev(s.Name, Type.FromString "unit")
else
createStructure s parsedMetaModel


for t in parsedMetaModel.TypeAliases do
// printfn "%A" t.Name
Abbrev(t.Name, createTypeAlias t)

for e in parsedMetaModel.Enumerations do
createEnumeration e



}

let writeToFile path contents = File.WriteAllText(path, contents)
Expand Down
2 changes: 1 addition & 1 deletion tests/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ let main args =
| ShouldRunBenchmarks args ->
// `--filter *` to run all
Benchmarks.run args
| _ -> Expecto.Tests.runTestsWithCLIArgs [ Sequenced ] args Tests.tests
| _ -> Expecto.Tests.runTestsWithCLIArgs [ Sequenced ] args Ionide.LanguageServerProtocol.GenerateTests.tests

0 comments on commit 6df1ab7

Please sign in to comment.