| 10 | ) |
| 11 | |
| 12 | func TestClassParser(t *testing.T) { |
| 13 | tests := []struct { |
| 14 | name string |
| 15 | input string |
| 16 | expect int |
| 17 | assert func(t *testing.T, classes []phpClass) |
| 18 | }{ |
| 19 | { |
| 20 | name: "single class", |
| 21 | input: `package main |
| 22 | |
| 23 | //export_php:class User |
| 24 | type UserStruct struct { |
| 25 | name string |
| 26 | Age int |
| 27 | }`, |
| 28 | expect: 1, |
| 29 | assert: func(t *testing.T, classes []phpClass) { |
| 30 | c := classes[0] |
| 31 | assert.Equal(t, "User", c.Name) |
| 32 | assert.Equal(t, "UserStruct", c.GoStruct) |
| 33 | assert.Len(t, c.Properties, 2) |
| 34 | }, |
| 35 | }, |
| 36 | { |
| 37 | name: "multiple classes", |
| 38 | input: `package main |
| 39 | |
| 40 | //export_php:class User |
| 41 | type UserStruct struct { |
| 42 | name string |
| 43 | Age int |
| 44 | } |
| 45 | |
| 46 | //export_php:class Product |
| 47 | type ProductStruct struct { |
| 48 | Title string |
| 49 | Price float64 |
| 50 | }`, |
| 51 | expect: 2, |
| 52 | }, |
| 53 | { |
| 54 | name: "no php classes", |
| 55 | input: `package main |
| 56 | |
| 57 | type RegularStruct struct { |
| 58 | Data string |
| 59 | }`, |
| 60 | expect: 0, |
| 61 | }, |
| 62 | { |
| 63 | name: "class with nullable fields", |
| 64 | input: `package main |
| 65 | |
| 66 | //export_php:class OptionalData |
| 67 | type OptionalStruct struct { |
| 68 | Required string |
| 69 | Optional *string |