Skip to content

Modules

Background

Given a file named "pen.json" with:

{
  "type": "library",
  "dependencies": {}
}

Import a function from a module

Given a file named "Foo.pen" with:

Foo = \() number {
  42
}

And a file named "Bar.pen" with:

import 'Foo

Bar = \() number {
  Foo'Foo()
}

When I run pen build

Then the exit status should be 0.

Import a type alias from a module

Given a file named "Foo.pen" with:

type Foo = number

And a file named "Bar.pen" with:

import 'Foo

type Bar = Foo'Foo

When I run pen build

Then the exit status should be 0.

Import a function from a nested module

Given a file named "Foo/Foo.pen" with:

Foo = \() number {
  42
}

And a file named "Bar.pen" with:

import 'Foo'Foo

Bar = \() number {
  Foo'Foo()
}

When I run pen build

Then the exit status should be 0.

Import a module with a custom prefix

Given a file named "Foo.pen" with:

Foo = \() number {
  42
}

And a file named "Bar.pen" with:

import 'Foo as Bar

Bar = \() number {
  Bar'Foo()
}

When I run pen build

Then the exit status should be 0.

Import a type definition with no prefix

Given a file named "Foo.pen" with:

type Foo {}

And a file named "Bar.pen" with:

import 'Foo { Foo }

type Bar = Foo

When I run pen build

Then the exit status should be 0.

Import a type alias with no prefix

Given a file named "Foo.pen" with:

type Foo = number

And a file named "Bar.pen" with:

import 'Foo { Foo }

type Bar = Foo

When I run pen build

Then the exit status should be 0.

Import a function with no prefix

Given a file named "Foo.pen" with:

Foo = \() number {
  42
}

And a file named "Bar.pen" with:

import 'Foo { Foo }

Bar = \() number {
  Foo()
}

When I run pen build

Then the exit status should be 0.