Skip to content
This repository was archived by the owner on Jul 22, 2022. It is now read-only.

Commit c59f3d1

Browse files
committed
Add Swift support
1 parent 695d167 commit c59f3d1

File tree

5 files changed

+45
-3
lines changed

5 files changed

+45
-3
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
- [PyPy](https://www.pypy.org/)
4343
- [Ruby](https://www.ruby-lang.org/en/)
4444
- [`ruby`](https://www.ruby-lang.org/en/downloads/)
45+
- [Swift](https://swift.org/)
46+
- [`swiftc`](https://swift.org/swift-compiler/)
4547

4648

4749
## Installation
@@ -77,7 +79,7 @@ sudo make install # python3 setup.py install
7779
## Usage
7880
```python
7981
>>> from dockerjudge import judge
80-
>>> from dockerjudge.processor import GCC, Clang, Bash, Python, Node, OpenJDK, PHP, Ruby, Mono
82+
>>> from dockerjudge.processor import GCC, Clang, Bash, Python, Node, OpenJDK, PHP, Ruby, Mono, Swift
8183
>>>
8284
>>> judge(
8385
... GCC(GCC.Language.c), # or `GCC('c')` / `GCC('C')`, which means compile the source code in the C programming language with `gcc` command
@@ -364,6 +366,14 @@ sudo make install # python3 setup.py install
364366
b'Compilation successful\r\n'
365367
b'Compilation took 00:00:00.0000000\n'
366368
]
369+
>>>
370+
>>> judge(Swift(), b'print("Hello, world!")', [(b'', b'Hello, world!')]) # Swift
371+
[
372+
[
373+
(<Status.AC: 'Accepted'>, (b'Hello, world!\n', b''), 0.2)
374+
],
375+
b''
376+
]
367377
```
368378

369379

README.zh_Hans_CN.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
- [PyPy](https://www.pypy.org/)
4343
- [Ruby](https://www.ruby-lang.org/zh_cn/)
4444
- [`ruby`](https://www.ruby-lang.org/zh_cn/downloads/)
45+
- [Swift](https://swift.org/)
46+
- [`swiftc`](https://swift.org/swift-compiler/)
4547

4648

4749
## 安装
@@ -77,7 +79,7 @@ sudo make install # python3 setup.py install
7779
## 用法示例
7880
```python
7981
>>> from dockerjudge import judge
80-
>>> from dockerjudge.processor import GCC, Clang, Bash, Python, Node, OpenJDK, PHP, Ruby, Mono
82+
>>> from dockerjudge.processor import GCC, Clang, Bash, Python, Node, OpenJDK, PHP, Ruby, Mono, Swift
8183
>>>
8284
>>> judge(
8385
... GCC(GCC.Language.c), # 或 `GCC('c')` / `GCC('C')`,意为用 `gcc` 命令编译 C 语言源码
@@ -364,6 +366,14 @@ sudo make install # python3 setup.py install
364366
b'Compilation successful\r\n'
365367
b'Compilation took 00:00:00.0000000\n'
366368
]
369+
>>>
370+
>>> judge(Swift(), b'print("Hello, world!")', [(b'', b'Hello, world!')]) # Swift
371+
[
372+
[
373+
(<Status.AC: 'Accepted'>, (b'Hello, world!\n', b''), 0.2)
374+
],
375+
b''
376+
]
367377
```
368378

369379

docker-pull.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ docker pull pypy:3 # For pypy3
1515
docker pull python:2 # For python2
1616
docker pull python:3 # For python3
1717
docker pull ruby # For ruby
18+
docker pull swift # For swiftc

dockerjudge/processor.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,13 @@ def __init__(self, version=None):
218218
self.source = 'ruby.rb'
219219
self.compile = ['ruby', '-wc', self.source]
220220
self.judge = f'ruby {self.source}'
221+
222+
223+
class Swift(Processor):
224+
'Swift'
225+
226+
def __init__(self, version=None):
227+
self.image = self._get_image_with_tag('swift', version)
228+
self.source = 'main.swift'
229+
self.compile = ['swiftc', self.source]
230+
self.judge = './main'

test_dockerjudge.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from dockerjudge import judge
88
from dockerjudge.processor import (Bash, Clang, GCC, Go, Mono, Node, OpenJDK,
9-
PHP, PyPy, Python, Ruby)
9+
PHP, PyPy, Python, Ruby, Swift)
1010
from dockerjudge.status import Status
1111

1212

@@ -430,5 +430,16 @@ def test_vb(self):
430430
self.assertEqual(result[0][0][0], Status.AC)
431431

432432

433+
class TestSwift(unittest.TestCase):
434+
435+
def test_swiftc(self):
436+
result = judge(
437+
Swift(),
438+
b'print("Hello, world!")',
439+
[(b'', b'Hello, world!')]
440+
)
441+
self.assertEqual(result[0][0][0], Status.AC)
442+
443+
433444
if __name__ == '__main__':
434445
unittest.main()

0 commit comments

Comments
 (0)