mirror of
https://github.com/aNNiMON/Own-Programming-Language-Tutorial.git
synced 2024-09-20 00:34:20 +03:00
Update README
This commit is contained in:
parent
d1c7a67817
commit
99a95a044f
@ -8,7 +8,7 @@ OwnLang - dynamic functional programming language inspired by Scala and Python.
|
||||
|
||||
| Free | Pro | Desktop |
|
||||
| :--: | :-: | :-----: |
|
||||
| [![Free](https://developer.android.com/images/brand/en_generic_rgb_wo_45.png)](https://play.google.com/store/apps/details?id=com.annimon.ownlang.free) | [![Pro](https://developer.android.com/images/brand/en_generic_rgb_wo_45.png)](https://play.google.com/store/apps/details?id=com.annimon.ownlang) | [v1.5.0](https://github.com/aNNiMON/Own-Programming-Language-Tutorial/releases/tag/v1.5.0)
|
||||
| [![Free](https://developer.android.com/images/brand/en_generic_rgb_wo_45.png)](https://play.google.com/store/apps/details?id=com.annimon.ownlang.free) | [![Pro](https://developer.android.com/images/brand/en_generic_rgb_wo_45.png)](https://play.google.com/store/apps/details?id=com.annimon.ownlang) | [v1.5.0](https://github.com/aNNiMON/Own-Programming-Language-Tutorial/releases/tag/v1.5.0) |
|
||||
|
||||
Also available as AUR package:
|
||||
|
||||
@ -139,7 +139,7 @@ def patch_callback(v) {
|
||||
|
||||
## Build
|
||||
|
||||
Build using Gradle `./gradlew dist`
|
||||
Build using Gradle `./gradlew shadowJar`
|
||||
|
||||
or take a look to [latest release](https://github.com/aNNiMON/Own-Programming-Language-Tutorial/releases/latest) for binaries.
|
||||
|
||||
|
167
examples.own
167
examples.own
@ -1,167 +0,0 @@
|
||||
/*
|
||||
*
|
||||
* Automatic run examples for testing.
|
||||
* Have functions for special launch own scripts if need
|
||||
*
|
||||
*/
|
||||
|
||||
use date, files, robot, std
|
||||
|
||||
DEBUG = true
|
||||
EXAMPLES_DIR = "examples"
|
||||
REPORT_PATH = "F:/report.txt"
|
||||
EXEC_TEMPLATE = "cmd /U /C \"ownlang -f %s %s >> %s 2>&1\""
|
||||
|
||||
// Main list of examples. Contains predefined examples with custom executing params
|
||||
listExamples = {
|
||||
/* template
|
||||
"program_name": {
|
||||
"isRun": false,
|
||||
"path": "" // relative path to program
|
||||
"args": [], // additional args for run
|
||||
"prelaunch": "", // pre-launch other application, e.g. start server
|
||||
},
|
||||
*/
|
||||
"fx_basic_shapes.own": {
|
||||
"isRun": false,
|
||||
"path": ""
|
||||
"args": [],
|
||||
"prelaunch": "",
|
||||
},
|
||||
"fx_event_handlers.own": {
|
||||
"isRun": false,
|
||||
"path": ""
|
||||
"args": [],
|
||||
"prelaunch": "",
|
||||
},
|
||||
"fx_global_alpha.own": {
|
||||
"isRun": false,
|
||||
"path": ""
|
||||
"args": [],
|
||||
"prelaunch": "",
|
||||
},
|
||||
"fx_image_negate.own": {
|
||||
"isRun": false,
|
||||
"path": ""
|
||||
"args": [],
|
||||
"prelaunch": "",
|
||||
},
|
||||
"fx_image.own": {
|
||||
"isRun": false,
|
||||
"path": ""
|
||||
"args": [],
|
||||
"prelaunch": "",
|
||||
},
|
||||
"fx_koch_snowflake.own": {
|
||||
"isRun": false,
|
||||
"path": ""
|
||||
"args": [],
|
||||
"prelaunch": "",
|
||||
},
|
||||
"fx_rotation.own": {
|
||||
"isRun": false,
|
||||
"path": ""
|
||||
"args": [],
|
||||
"prelaunch": "",
|
||||
},
|
||||
"okhttp_telegram_sendvoice.own": {
|
||||
"isRun": false,
|
||||
"path": ""
|
||||
"args": [],
|
||||
"prelaunch": "",
|
||||
},
|
||||
"telegram_api.own": {
|
||||
"isRun": false,
|
||||
"path": ""
|
||||
"args": [],
|
||||
"prelaunch": "",
|
||||
},
|
||||
"okhttp_imgur_upload.own": {
|
||||
"isRun": false,
|
||||
"path": ""
|
||||
"args": [],
|
||||
"prelaunch": "",
|
||||
},
|
||||
"okhttp_websocket.own": {
|
||||
"isRun": false,
|
||||
"path": ""
|
||||
"args": [],
|
||||
"prelaunch": "",
|
||||
},
|
||||
"pipes_online.own": {
|
||||
"isRun": false,
|
||||
"path": ""
|
||||
"args": [],
|
||||
"prelaunch": "",
|
||||
},
|
||||
}
|
||||
|
||||
def debug(something) {
|
||||
if !DEBUG return 0
|
||||
|
||||
println sprintf("[%s] %s", newDate(), something)
|
||||
}
|
||||
|
||||
// Algorithm: get list of examples, filter and add to main list of examples
|
||||
def readExamples() {
|
||||
examplesDir = fopen(EXAMPLES_DIR, "")
|
||||
dirs = listFiles(examplesDir)
|
||||
|
||||
for dir : dirs {
|
||||
relativeDirPath = EXAMPLES_DIR + "/" + dir
|
||||
subDir = fopen(relativeDirPath, "")
|
||||
if (!isDirectory(subDir) || dir == "." || dir == "..") continue
|
||||
files = listFiles(subDir)
|
||||
for file : files {
|
||||
if (indexOf(file, ".own") < 0 || dir == "." || dir == "..") {
|
||||
debug(file + "not ownlang application or sub directory")
|
||||
continue
|
||||
}
|
||||
if (arrayKeyExists(file, listExamples)) {
|
||||
debug(file + " exists in main list")
|
||||
continue
|
||||
}
|
||||
program = {
|
||||
"isRun": true,
|
||||
"path": relativeDirPath + "/" + file
|
||||
"args": [],
|
||||
"prelaunch": "",
|
||||
}
|
||||
listExamples[file] = program
|
||||
}
|
||||
}
|
||||
return listExamples
|
||||
}
|
||||
|
||||
readExamples()
|
||||
|
||||
// remove old report
|
||||
if exists(REPORT_PATH) {
|
||||
delete(REPORT_PATH)
|
||||
}
|
||||
|
||||
// main task
|
||||
for name, program : listExamples {
|
||||
if !program.isRun {
|
||||
println "Skip: " + name
|
||||
continue
|
||||
}
|
||||
|
||||
println "Executing: " + name
|
||||
|
||||
reportBeforeExec = sprintf("cmd /U /C \"echo %s\n >> %s", program.path, REPORT_PATH)
|
||||
execProcessAndWait(reportBeforeExec)
|
||||
|
||||
if length(trim(program.prelaunch)) > 0 {
|
||||
println "Pre-launch: " + program.pre-launch
|
||||
execProcessAndWait(program.pre-launch)
|
||||
}
|
||||
|
||||
execString = sprintf(EXEC_TEMPLATE, program.path, join(program.args, " "), REPORT_PATH)
|
||||
debug(execString)
|
||||
exitCode = execProcessAndWait(execString)
|
||||
println "Exit code: " + exitCode
|
||||
|
||||
reportAfterExec = sprintf("cmd /U /C \"echo %s\n >> %s", "*"*19, REPORT_PATH)
|
||||
execProcessAndWait(reportAfterExec)
|
||||
}
|
128
tests.own
128
tests.own
@ -1,128 +0,0 @@
|
||||
use ounit, types, functional, date, files
|
||||
|
||||
def testAdditionOnNumbers() {
|
||||
assertEquals(6, 0 + 1 + 2 + 3)
|
||||
}
|
||||
|
||||
def testSubtractionOnNumbers() {
|
||||
assertEquals(-6, 0 - 1 - 2 - 3)
|
||||
}
|
||||
|
||||
def testPrefixIncrement() {
|
||||
a = 8
|
||||
assertEquals(9, ++a)
|
||||
assertEquals(9, a)
|
||||
}
|
||||
|
||||
def testPostfixIncrement() {
|
||||
a = 8
|
||||
assertEquals(8, a++)
|
||||
assertEquals(9, a)
|
||||
}
|
||||
|
||||
def testStringReversing() {
|
||||
assertEquals("tset", -"test")
|
||||
}
|
||||
|
||||
def testStringMultiplication() {
|
||||
assertEquals("******", "*" * 6)
|
||||
}
|
||||
|
||||
def testTypes() {
|
||||
assertSameType(0, 0.0)
|
||||
}
|
||||
|
||||
/*def testFail() {
|
||||
assertTrue(false)
|
||||
}*/
|
||||
|
||||
def testScope() {
|
||||
x = 5
|
||||
def func() {
|
||||
assertEquals(5, x)
|
||||
x += 10
|
||||
assertEquals(15, x)
|
||||
}
|
||||
func();
|
||||
assertEquals(15, x)
|
||||
}
|
||||
|
||||
def testFibonacci() {
|
||||
def fib(n) {
|
||||
if n < 2 return n
|
||||
return fib(n-2) + fib(n-1)
|
||||
}
|
||||
assertEquals(3, fib(4))
|
||||
assertEquals(21, fib(8))
|
||||
}
|
||||
|
||||
def testFunctionalChain() {
|
||||
data = [1,2,3,4,5,6,7]
|
||||
result = chain(data,
|
||||
::filter, def(x) = x <= 4,
|
||||
::sortby, def(x) = -x,
|
||||
::map, def(x) = x * 2,
|
||||
)
|
||||
assertEquals([8,6,4,2], result)
|
||||
}
|
||||
|
||||
|
||||
// --- Date
|
||||
def testNewDate() {
|
||||
d = newDate(2016, 04, 10)
|
||||
assertEquals(2016, d.year)
|
||||
assertEquals(4, d.month)
|
||||
assertEquals(10, d.day)
|
||||
assertEquals(0, d.hour)
|
||||
assertEquals(0, d.minute)
|
||||
assertEquals(0, d.second)
|
||||
assertEquals(0, d.millisecond)
|
||||
}
|
||||
|
||||
def testCompareDates() {
|
||||
assertTrue(newDate(2016, 04, 10) > newDate(2015, 03, 11))
|
||||
assertTrue(newDate(2012, 04, 10) < newDate(2015, 03, 11))
|
||||
assertTrue(newDate(2015, 03, 11, 0, 0, 0) == newDate(2015, 03, 11))
|
||||
}
|
||||
|
||||
def testDateFormat() {
|
||||
d = formatDate(newDate(2016, 04, 10), newFormat("yyyy/MM/dd HH:mm:ss"))
|
||||
assertEquals("2016/05/10 00:00:00", d)
|
||||
}
|
||||
|
||||
def testDateParse() {
|
||||
d = parseDate("2016/05/10", newFormat("yyyy/MM/dd"))
|
||||
assertEquals(2016, d.year)
|
||||
assertEquals(4, d.month)
|
||||
assertEquals(10, d.day)
|
||||
assertEquals(0, d.hour)
|
||||
}
|
||||
|
||||
// --- Files
|
||||
def testFiles() {
|
||||
// writeLong
|
||||
f = fopen("test.file", "wb")
|
||||
writeLong(f, 1002003004005006007)
|
||||
flush(f)
|
||||
fclose(f)
|
||||
|
||||
// append & writeFloat
|
||||
fpNumber = 100200.3004005006007
|
||||
f = fopen("test.file", "wb+")
|
||||
writeFloat(f, fpNumber)
|
||||
flush(f)
|
||||
fclose(f)
|
||||
|
||||
f = fopen("test.file", "rb")
|
||||
assertEquals(1002003004005006007, readLong(f))
|
||||
assertEquals(float(fpNumber), readFloat(f))
|
||||
assertEquals(-1, readInt(f)) // EOF
|
||||
assertEquals(0, FILES_COMPARATOR(f, f))
|
||||
fclose(f)
|
||||
|
||||
f = fopen("test.file", "i")
|
||||
delete(f)
|
||||
fclose(f)
|
||||
}
|
||||
|
||||
println runTests()
|
Loading…
Reference in New Issue
Block a user