mabdi / small-amp

Test Amplification for Pharo
MIT License
5 stars 4 forks source link

Check this method. #89

Open mabdi opened 4 years ago

mabdi commented 4 years ago

This method from zinc project:

testMultiValues
    | dictionary values keys |
    dictionary := ZnMultiValueDictionary new.
    dictionary at: 'foo' add: 1; at: 'foo' add: 2.
    self assert: (dictionary at: 'foo') = #(1 2).
    self assert: dictionary keys asArray = #('foo').
    values := OrderedCollection new.
    keys := OrderedCollection new.
    dictionary keysAndValuesDo: [ :key :value | keys add: key. values add: value ].
    self assert: values = (OrderedCollection with: 1 with: 2).
    self assert: keys = (OrderedCollection with: 'foo' with: 'foo')

is converted to it:

testMultiValues_amp_L20
    <madeBySmallAmp>
    | dictionary values keys |
    dictionary := ZnMultiValueDictionary new.
    dictionary := dictionary
        at: 'foo' add: 1;
        at: 'foo' add: 1.
    values := OrderedCollection new.
    keys := OrderedCollection new.
     dictionary
                keysAndValuesDo: [ :key :value | 
                    keys add: key.
                    values add: value ] 

Line 5 of Which does not look correct. Why the dictionary variable is set to the result of Dictionary>>#at:add: ?

mabdi commented 4 years ago

And:

testMergedFields
    | request form mergedFields |
    request := ZnRequest post: 'http://host.com/foo?x=1&y=2&x=3'.
    form := ZnApplicationFormUrlEncodedEntity new.
    form
        at: #z put: '100';
        at: #z add: '200';
        at: #y put: '0'.
    request entity: form.
    mergedFields := request mergedFields.
    self assert: mergedFields keys sorted equals: #(x y z).
    self assert: (mergedFields at: #x) sorted equals: #('1' '3').
    self assert: (mergedFields at: #y) sorted equals: #('0' '2').
    self assert: (mergedFields at: #z) sorted equals: #('100' '200')

I get:

request := ZnRequest post: 'http:/D/host.com/foo?x=1&y=2&x=3'.
    form := ZnApplicationFormUrlEncodedEntity new.
    form := form
        at: #z put: '100';
        at: #z add: '200';
        at: #y put: '0'.
mabdi commented 4 years ago
testFailValidateInterfaceTypeExtension
    | valid |
    schema := self parseSchema: '
                        schema { 
                            query: Query
                        }
                        type GQLFilm implements RelevantData { 
                            name: String
                        }
                        interface RelevantData{
                            name : String
                        }
                        extend interface OtherInterface{
                            id: String
                        }'.
    self should: [ schema validate ] raise: GQLValidationException.

    schema := self parseSchema: '
                        schema { 
                            query: Query
                        }
                        type GQLFilm implements RelevantData { 
                            name: String
                        }
                        interface RelevantData{
                            name : String
                        }
                        extend interface RelevantData{
                            name: String
                            id: String
                        }'.
    self should: [ schema validate ] raise: GQLValidationException.

    schema := self parseSchema: '
                        schema { 
                            query: GQLTestFilm
                        }
                        interface NamedEntity{
                            name: String
                        }
                        extend interface NamedEntity{
                            id: String
                        }
                        type GQLTestFilm implements NamedEntity{
                            name: String
                        }'.
    self should: [ schema validate ] raise: GQLValidationException.

    schema := self parseSchema: '
                        schema { 
                            query: GQLTestFilm
                        }
                        interface NamedEntity{
                            name: String
                        }
                        extend interface NamedEntity{
                            id: String
                        }
                        type GQLTestFilm{
                            filmName: String
                        }
                        extend type GQLTestFilm implements NamedEntity{
                            id: String
                        }'.
    valid := schema validate.
    self should: [ schema validate ] raise: GQLValidationException.

I get:

testFailValidateInterfaceTypeExtension_amp
    "I test correctness of: 

- `^ query` in method: `GQLSSchemaNode >> #query` when {#query->nil}

"

    <madeBySmallAmp>
    | valid |
    schema := self
        parseSchema:
            '
                        schema { 
                            query: Query
                        }
                        type GQLFilm implements RelevantData { 
                            name: String
                        }
                        interface RelevantData{
                            name : String
                        }
                        extend interface OtherInterface{
                            id: String
                        }';
        assert: schema query isNil;
        parseSchema:
            '
                        schema { 
                            query: Query
                        }
                        type GQLFilm implements RelevantData { 
                            name: String
                        }
                        interface RelevantData{
                            name : String
                        }
                        extend interface RelevantData{
                            name: String
                            id: String
                        }';
        parseSchema:
            '
                        schema { 
                            query: GQLTestFilm
                        }
                        interface NamedEntity{
                            name: String
                        }
                        extend interface NamedEntity{
                            id: String
                        }
                        type GQLTestFilm implements NamedEntity{
                            name: String
                        }'.
    valid := (self
        parseSchema:
            '
                        schema { 
                            query: GQLTestFilm
                        }
                        interface NamedEntity{
                            name: String
                        }
                        extend interface NamedEntity{
                            id: String
                        }
                        type GQLTestFilm{
                            filmName: String
                        }
                        extend type GQLTestFilm implements NamedEntity{
                            id: String
                        }') validate

(Line with assert) It should first set schema then assert the value. Using cascade in this example is not correct.