| 44 | } |
| 45 | |
| 46 | func TestCreateDoc(t *testing.T) { |
| 47 | Operators = nil |
| 48 | Builtins = nil |
| 49 | doc := CreateDoc(&Env{}) |
| 50 | expected := &Context{ |
| 51 | Variables: map[Identifier]*Type{ |
| 52 | "Tweets": { |
| 53 | Kind: "array", |
| 54 | Type: &Type{ |
| 55 | Kind: "struct", |
| 56 | Name: "Tweet", |
| 57 | }, |
| 58 | }, |
| 59 | "Config": { |
| 60 | Kind: "struct", |
| 61 | Fields: map[Identifier]*Type{ |
| 62 | "MaxSize": {Kind: "int"}, |
| 63 | }, |
| 64 | }, |
| 65 | "Env": { |
| 66 | Kind: "map", |
| 67 | Key: &Type{Kind: "string"}, |
| 68 | Type: &Type{Kind: "any"}, |
| 69 | }, |
| 70 | "Duration": { |
| 71 | Kind: "func", |
| 72 | Arguments: []*Type{ |
| 73 | {Kind: "string"}, |
| 74 | }, |
| 75 | Return: &Type{Kind: "struct", Name: "Duration"}, |
| 76 | }, |
| 77 | "TimeWeekday": { |
| 78 | Name: "time.Weekday", |
| 79 | Kind: "struct", |
| 80 | }, |
| 81 | "Weekday": { |
| 82 | Name: "Weekday", |
| 83 | Kind: "struct", |
| 84 | }, |
| 85 | }, |
| 86 | Types: map[TypeName]*Type{ |
| 87 | "Tweet": { |
| 88 | Kind: "struct", |
| 89 | Fields: map[Identifier]*Type{ |
| 90 | "Size": {Kind: "int"}, |
| 91 | "Message": {Kind: "string"}, |
| 92 | }, |
| 93 | }, |
| 94 | "Duration": { |
| 95 | Kind: "struct", |
| 96 | Fields: map[Identifier]*Type{ |
| 97 | "String": { |
| 98 | Kind: "func", |
| 99 | Arguments: []*Type{}, |
| 100 | Return: &Type{ |
| 101 | Kind: "string", |
| 102 | }, |
| 103 | }, |