Skip to content

Commit

Permalink
Use Okay to validate parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
cdlm committed Mar 25, 2019
1 parent 9463855 commit 93e8f4c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/BaselineOfClap/BaselineOfClap.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Class {
BaselineOfClap >> baseline: spec [
<baseline>
spec for: #common do: [ spec
baseline: 'Okay' with: [ spec repository: 'github://cdlm/okay-st' ];

package: 'Clap-Core';
package: 'Clap-CommandLine' with: [ spec requires: #('Clap-Core') ];
package: 'Clap-Tests' with: [ spec requires: #('Clap-Core' 'Clap-Examples') ];
Expand Down
37 changes: 37 additions & 0 deletions src/Clap-Tests/ClapArgumentValidationTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Class {
#name : #ClapArgumentValidationTest,
#superclass : #TestCase,
#category : #'Clap-Tests-Validations'
}

{ #category : #tests }
ClapArgumentValidationTest >> testFailValidationWhenMissingMandatoryArgument [
| flag match report |
flag := (ClapFlag withName: 'lang')
add: (ClapPositional withName: 'langCode');
validations: [ :arg | {
Okay if: [ :it | (it atName: 'langCode') isExplicit ]
} collect: [ :each | each validate: arg ] ].

match := flag match: #('--lang').
report := ClapValidationReport success.
match validateOn: report.

self assert: report isFailure
]

{ #category : #tests }
ClapArgumentValidationTest >> testPassValidationWithMandatoryArgument [
| flag match report |
flag := (ClapFlag withName: 'lang')
add: (ClapPositional withName: 'langCode');
validations: [ :arg | {
Okay if: [ :it | (it atName: 'langCode') isExplicit ]
} collect: [ :each | each validate: arg ] ].

match := flag match: #('--lang' 'eo').
report := ClapValidationReport success.
match validateOn: report.

self assert: report isSuccess
]
2 changes: 1 addition & 1 deletion src/Clap-Tests/ClapHelloWorldTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Class {
#instVars : [
'hello'
],
#category : 'Clap-Tests-Integration'
#category : #'Clap-Tests-Integration'
}

{ #category : #running }
Expand Down

0 comments on commit 93e8f4c

Please sign in to comment.