Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to test a function where the first arg is Data #282

Open
shinokada opened this issue Nov 15, 2022 · 1 comment
Open

How to test a function where the first arg is Data #282

shinokada opened this issue Nov 15, 2022 · 1 comment

Comments

@shinokada
Copy link

shinokada commented Nov 15, 2022

The first test works using Data and result().
But I'm not sure how to test the second one. The function insert_blank_above_a takes two arguments, input and a string.
How to test a function that takes more than one arguments?
I have functions with three, four arguments as well.

Can I use Data as a argument?

Describe 'Space editor'
  Data
    #|foo
    #|bar
    #|baz
  End

  Describe 'double_space'
    It 'outputs no more than one blank line between lines of text'
      result() {
        %text
        #|foo
        #|
        #|bar
        #|
        #|baz
      }

      When call double_space 
      The output should eq "$(result)"
    End
  End

  Describe 'insert_blank_above_a'
    It 'outputs no more than one blank line between lines of text'
      result() {
        %text
        #|foo
        #|bar
        #|
        #|baz
      }

      When call insert_blank_above_a Data bar
      The output should eq "$(result)"
    End
  End
End
@shinokada shinokada changed the title How to test a function with more than one arg How to test a function where the first arg is Data Nov 16, 2022
@LukeSavefrogs
Copy link
Contributor

LukeSavefrogs commented Nov 23, 2022

You have used the Data directive in the wrong way.

As you can see from the docs the Data block MUST precede the When directive, so in your case it should be:

Data
  #|foo
  #|bar
  #|baz
End

When call insert_blank_above_a Data bar
The output should eq "$(result)"

However, i don't understand what you want to do...
The insert_blank_above_a needs 2 parameters that change every time?

Maybe you need the Parameters directive?

Data[:*] vs Parameters[:*]

The difference is:

  • Data directives: Passes data through STDIN (i.e. awk, cat)
  • Parameters directives: Data is available as a parameter ($1..$N)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants