-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial unit tests for script and config formatting
Signed-off-by: Ben Sherman <[email protected]>
- Loading branch information
1 parent
27886b2
commit 16e92d2
Showing
4 changed files
with
209 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 2013-2024, Seqera Labs | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package nextflow.lsp | ||
|
||
import java.util.concurrent.CompletableFuture | ||
|
||
import org.eclipse.lsp4j.MessageActionItem | ||
import org.eclipse.lsp4j.MessageParams | ||
import org.eclipse.lsp4j.PublishDiagnosticsParams | ||
import org.eclipse.lsp4j.ShowMessageRequestParams | ||
import org.eclipse.lsp4j.services.LanguageClient | ||
|
||
/** | ||
* | ||
* @author Ben Sherman <[email protected]> | ||
*/ | ||
class TestLanguageClient implements LanguageClient { | ||
|
||
@Override | ||
public void telemetryEvent(Object object) { | ||
} | ||
|
||
@Override | ||
public CompletableFuture<MessageActionItem> showMessageRequest(ShowMessageRequestParams requestParams) { | ||
return null | ||
} | ||
|
||
@Override | ||
public void showMessage(MessageParams messageParams) { | ||
} | ||
|
||
@Override | ||
public void publishDiagnostics(PublishDiagnosticsParams diagnostics) { | ||
} | ||
|
||
@Override | ||
public void logMessage(MessageParams message) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/test/groovy/nextflow/lsp/services/config/ConfigFormattingTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright 2013-2024, Seqera Labs | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package nextflow.lsp.services.config | ||
|
||
import java.nio.file.Files | ||
import java.nio.file.Path | ||
|
||
import nextflow.lsp.services.util.FormattingOptions | ||
import nextflow.lsp.TestLanguageClient | ||
import org.eclipse.lsp4j.DidOpenTextDocumentParams | ||
import org.eclipse.lsp4j.Position | ||
import org.eclipse.lsp4j.TextDocumentItem | ||
import spock.lang.Specification | ||
|
||
/** | ||
* | ||
* @author Ben Sherman <[email protected]> | ||
*/ | ||
class ConfigFormattingTest extends Specification { | ||
|
||
String openAndFormat(ConfigService service, Path filePath, String contents) { | ||
def uri = filePath.toUri() | ||
def textDocumentItem = new TextDocumentItem(uri.toString(), 'nextflow-config', 1, contents) | ||
service.didOpen(new DidOpenTextDocumentParams(textDocumentItem)) | ||
def textEdits = service.formatting(uri, new FormattingOptions(4, true, false)) | ||
return textEdits.first().getNewText() | ||
} | ||
|
||
def 'should format a config file' () { | ||
given: | ||
def workspaceRoot = Path.of(System.getProperty('user.dir')).resolve('build/test_workspace/') | ||
if( !Files.exists(workspaceRoot) ) | ||
workspaceRoot.toFile().mkdirs() | ||
|
||
def service = new ConfigService() | ||
service.connect(new TestLanguageClient()) | ||
service.initialize(workspaceRoot.toUri().toString(), Collections.emptyList(), false) | ||
|
||
when: | ||
def filePath = workspaceRoot.resolve('nextflow.config') | ||
def contents = '''\ | ||
process.cpus = 2 ; process.memory = 8.GB | ||
'''.stripIndent() | ||
then: | ||
openAndFormat(service, filePath, contents) == '''\ | ||
process.cpus = 2 | ||
process.memory = 8.GB | ||
'''.stripIndent() | ||
|
||
when: | ||
contents = '''\ | ||
process.cpus = 2 | ||
process.memory = 8.GB | ||
'''.stripIndent() | ||
then: | ||
openAndFormat(service, filePath, contents) == '''\ | ||
process.cpus = 2 | ||
process.memory = 8.GB | ||
'''.stripIndent() | ||
} | ||
|
||
} |
79 changes: 79 additions & 0 deletions
79
src/test/groovy/nextflow/lsp/services/script/ScriptFormattingTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright 2013-2024, Seqera Labs | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package nextflow.lsp.services.script | ||
|
||
import java.nio.file.Files | ||
import java.nio.file.Path | ||
|
||
import nextflow.lsp.services.util.FormattingOptions | ||
import nextflow.lsp.TestLanguageClient | ||
import org.eclipse.lsp4j.DidOpenTextDocumentParams | ||
import org.eclipse.lsp4j.Position | ||
import org.eclipse.lsp4j.TextDocumentItem | ||
import spock.lang.Specification | ||
|
||
/** | ||
* | ||
* @author Ben Sherman <[email protected]> | ||
*/ | ||
class ScriptFormattingTest extends Specification { | ||
|
||
String openAndFormat(ScriptService service, Path filePath, String contents) { | ||
def uri = filePath.toUri() | ||
def textDocumentItem = new TextDocumentItem(uri.toString(), 'nextflow', 1, contents) | ||
service.didOpen(new DidOpenTextDocumentParams(textDocumentItem)) | ||
def textEdits = service.formatting(uri, new FormattingOptions(4, true, false)) | ||
return textEdits.first().getNewText() | ||
} | ||
|
||
def 'should format a script' () { | ||
given: | ||
def workspaceRoot = Path.of(System.getProperty('user.dir')).resolve('build/test_workspace/') | ||
if( !Files.exists(workspaceRoot) ) | ||
workspaceRoot.toFile().mkdirs() | ||
|
||
def service = new ScriptService() | ||
service.connect(new TestLanguageClient()) | ||
service.initialize(workspaceRoot.toUri().toString(), Collections.emptyList(), false) | ||
|
||
when: | ||
def filePath = workspaceRoot.resolve('main.nf') | ||
def contents = '''\ | ||
workflow { println 'Hello!' } | ||
'''.stripIndent() | ||
then: | ||
openAndFormat(service, filePath, contents) == '''\ | ||
workflow { | ||
println('Hello!') | ||
} | ||
'''.stripIndent() | ||
|
||
when: | ||
contents = '''\ | ||
workflow { | ||
println('Hello!') | ||
} | ||
'''.stripIndent() | ||
then: | ||
openAndFormat(service, filePath, contents) == '''\ | ||
workflow { | ||
println('Hello!') | ||
} | ||
'''.stripIndent() | ||
} | ||
|
||
} |