Skip to content

Commit

Permalink
Adding unit tests (#32)
Browse files Browse the repository at this point in the history
* Adding unit tests
  • Loading branch information
AnHeuermann authored Mar 13, 2024
1 parent 79ac3e4 commit 68ba244
Show file tree
Hide file tree
Showing 9 changed files with 321 additions and 114 deletions.
50 changes: 45 additions & 5 deletions .github/workflows/createPackage.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Create MetaModelica VS Code Extension
on:
name: CI
on:
push:
branches:
- main
Expand All @@ -8,29 +8,69 @@ on:
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup npm
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install the dependencies

- name: Install dependencies
run: npm install
- name: Build package

- name: Translate grammar to JSON
run: npm run prebuild

- name: Archive tmGrammar files
uses: actions/upload-artifact@v4
with:
name: tmGrammar.json
path: syntaxes/*.tmGrammar.json

- name: Build Package
if: always()
run: npm run build

- name: Archive vsix package
if: always()
uses: actions/upload-artifact@v4
with:
name: metamodelica.vsix
path: metamodelica-*.vsix

test:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup npm
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install dependencies
run: npm install

- name: Download tmGrammar files
uses: actions/download-artifact@v4
with:
name: tmGrammar.json
path: syntaxes

- name: Run Test
run: npm run test

release:
if: startsWith(github.ref, 'refs/tags/')
needs: build
needs: test
runs-on: ubuntu-latest
permissions:
contents: write
Expand Down
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
"version": "0.2.0",
"version": "0.2.0",
"configurations": [
{
"name": "Extension",
Expand Down
35 changes: 35 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "tmGrammar tests",
"type": "shell",
"command": "npx vscode-tmgrammar-test -c 'test/**/*.test.*'",
"group": "test",
"presentation": {
"reveal": "always",
"panel": "new",
},
"problemMatcher": {
"owner": "vscode-tmgrammar-test",
"fileLocation": [
"relative",
"${workspaceFolder}",
],
"pattern": [
{
"regexp": "^(ERROR)\\s([^:]+):(\\d+):(\\d+):(\\d+)\\s(.*)$",
"severity": 1,
"file": 2,
"line": 3,
"column": 4,
"endColumn": 5,
"message": 6,
},
],
}
}
]
}
78 changes: 56 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
[![Build Extension](https://github.com/AnHeuermann/modelica-language-vscode/actions/workflows/createPackage.yml/badge.svg)](https://github.com/AnHeuermann/modelica-language-vscode/actions/workflows/createPackage.yml)
[![Test](https://github.com/AnHeuermann/modelica-language-vscode/actions/workflows/ci.yml/badge.svg)](https://github.com/AnHeuermann/modelica-language-vscode/actions/workflows/ci.yml)

# MetaModelica and Susan in Visual Studio Code

This extension adds support for the Modelica, Optimica, MetaModelica and Susan languages
to Visual Studio Code.
This extension is meant to use for developers of OpenModelica.
If you want Modelica support use the great extension
[Modelica by SimplyDanny](https://marketplace.visualstudio.com/items?itemName=SimplyDanny.modelica)
This extension adds support for the Modelica, Optimica, MetaModelica and Susan
languages to Visual Studio Code. This extension is meant to use for developers
of OpenModelica. If you want Modelica support use the great extension [Modelica
by
SimplyDanny](https://marketplace.visualstudio.com/items?itemName=SimplyDanny.modelica)
which is the base for this extensions.

## Source

This extension is based on the Modelica extension taken from
[SimplyDanny/modelica-language-vscode](https://github.com/SimplyDanny/modelica-language-vscode)
This extension is based on the Modelica extension
[SimplyDanny/modelica-language-vscode](https://github.com/SimplyDanny/modelica-language-vscode).

## Features

Expand Down Expand Up @@ -43,29 +43,63 @@ This extension is based on the Modelica extension taken from

### Select MetaModelica as a language

* On the bottom-right corner, click on the *select language mode* button, if you have
created a new file it should display *Plain Text*.
* On the bottom-right corner, click on the *select language mode* button, if you
have created a new file it should display *Plain Text*.
* Select *MetaModelica* or *Susan* or *Modelica* in the list of languages.


Alternatively, saving the file with a `.mo` extension will allow VS Code to understand
that it is a MetaModelica file and automatically select the language. If it is a Modelica
file one has to manually change the language mode to *Modelica*.
The `.mop` extension will be associated with the Optimica language respectively.
The `.tpl` extension will be associated with Susan Template language.
Additional extensions can be connected to the languages in any `settings.json` file using
the `"files.associations"` setting.
Alternatively, saving the file with a `.mo` extension will allow VS Code to
understand that it is a MetaModelica file and automatically select the language.
If it is a Modelica file one has to manually change the language mode to
*Modelica*. The `.mop` extension will be associated with the Optimica language
respectively. The `.tpl` extension will be associated with Susan Template
language. Additional extensions can be connected to the languages in any
`settings.json` file using the `"files.associations"` setting.

### Using snippets

Just start to type and choose a snippet that may be proposed. Alternatively, use
`Ctrl+Shift+P` to open the command palette and type `Insert Snippet` to see a list of all
possible snippets to choose from.
`Ctrl+Shift+P` to open the command palette and type `Insert Snippet` to see a
list of all possible snippets to choose from.

## Development

Use the provided dev container to build and publish the extension. See
[https://code.visualstudio.com/api/working-with-extensions/publishing-extension#installation](code.visualstudio.com/api/working-with-extensions/publishing-extension).
There is a dev container available to build and publish the extension.
See
[https://code.visualstudio.com/api/working-with-extensions/publishing-extension#installation](code.visualstudio.com/api/working-with-extensions/publishing-extension)
for more details on the publishing process.

### Dependencies

- Node.js
- VSCode
- sh (or translate [yaml2json.sh](./yaml2json.sh) to your shell equivalent)

### Build

```bash
npm install
```

Translate the `*tmGrammar.yaml` files to `*.tmGrammar.json` JSON files.

```bash
npm run prebuild
```

### Test

Run the `tmGrammer tests` task:
- Open Command Palette (Ctrl+Shift+P)
- Type `tasks: Run task`
- Choose `tmGrammer tests`

or run it manually:

```bash
npx vscode-tmgrammar-test test/**/*.test.*
```

### Build Package

Generate .vsix package file:
```bash
Expand Down
12 changes: 6 additions & 6 deletions examples/LotkaVolterra.mo
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
model LotkaVolterra "Lotka-Volterra equations"
Real x(start = 1) "Prey";
Real y(start = 1) "Predator";
parameter Real lambda = 0.5;
input Real u;
Real x(start = 1) "Prey";
Real y(start = 1) "Predator";
parameter Real lambda = 0.5;
input Real u;
equation
der(x) = x - x * y - lambda * u;
der(y) = -y + x * y - u;
der(x) = x - x * y - lambda * u;
der(y) = -y + x * y - u;
end LotkaVolterra;
Loading

0 comments on commit 68ba244

Please sign in to comment.