Skip to content

Commit

Permalink
tests: add language-specific code sample tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ignace committed Dec 21, 2023
1 parent 3684f4e commit 07cb26b
Show file tree
Hide file tree
Showing 176 changed files with 7,589 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test-app/app/components/language-tests/abap.gts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { CodeBlock } from 'ember-shiki';

const codeExample = `
report zldbread no standard page heading.
tables: lfa1.
data: begin of t occurs 0,
linfr like lfa1-lifnr,
name1 like lfa1-name1,
end of t.
start-of-selection.
get lfa1.
clear t.
move-corresponding lfa1 to t.
append t.
end-of-selection.
sort t by name1.
loop at t.
write: / t-name1, t-lifnr.
endloop.
*- From https://sapbrainsonline.com/abap-tutorial/codes/reading-logical-database-using-abap-program.html -*`;

<template>
<CodeBlock @code={{codeExample}} @language="abap" />
</template>
34 changes: 34 additions & 0 deletions test-app/app/components/language-tests/actionscript-3.gts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { CodeBlock } from 'ember-shiki';

const codeExample = `
private function createParticles( count ):void{
var anchorPoint = 0;
for(var i:uint = 0; i < count; i++){
var particle:Object;
if( inactiveFireParticles.length > 0 ){
particle = inactiveFireParticles.shift();
}else {
particle = new Object();
fireParticles.push( particle );
}
particle.x = uint( Math.random() * frame.width * 0.1 ) + anchors[anchorPoint];
particle.y = frame.bottom;
particle.life = 70 + uint( Math.random() * 30 );
particle.size = 5 + uint( Math.random() * 10 );
if(particle.size > 12){
particle.size = 10;
}
particle.anchor = anchors[anchorPoint] + uint( Math.random() * 5 );
anchorPoint = (anchorPoint == 9)? 0 : anchorPoint + 1;
}
}
// From https://code.tutsplus.com/tutorials/actionscript-30-optimization-a-practical-example--active-11295`;

<template>
<CodeBlock @code={{codeExample}} @language="actionscript-3" />
</template>
30 changes: 30 additions & 0 deletions test-app/app/components/language-tests/ada.gts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { CodeBlock } from 'ember-shiki';

const codeExample = `
with
Ada.Text_IO,
Ada.Integer_Text_IO;
use Ada;
procedure fizz_buzz is
begin
for i in 1..100 loop
if i mod 15 = 0 then
Text_IO.Put_Line("fizz buzz");
elsif i mod 5 = 0 then
Text_IO.Put_Line("buzz");
elsif i mod 3 = 0 then
Text_IO.Put_Line("fizz");
else
Integer_Text_IO.put(i, Width => 0);
Text_IO.New_Line;
end if;
end loop;
end fizz_buzz;
-- From https://github.com/kylelk/ada-examples/blob/master/fizz_buzz.adb
`;

<template>
<CodeBlock @code={{codeExample}} @language="ada" />
</template>
47 changes: 47 additions & 0 deletions test-app/app/components/language-tests/apache.gts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { CodeBlock } from 'ember-shiki';

const codeExample = `
# Apache httpd v2.4 minimal configuration
# see https://wiki.apache.org/httpd/Minimal_Config for documentation
ServerRoot ${GITPOD_REPO_ROOT}
PidFile ${APACHE_PID_FILE}
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
# Modules as installed/activated via apt-get
IncludeOptional /etc/apache2/mods-enabled/*.load
IncludeOptional /etc/apache2/mods-enabled/*.conf
# Configure hostname and port for server
ServerName ${APACHE_SERVER_NAME}
Listen *:8080
# Configure Logging
LogFormat "%h %l %u %t \"%r\" %>s %b" common
CustomLog ${APACHE_LOG_DIR}/access.log common
ErrorLog ${APACHE_LOG_DIR}/error.log
# Never change this block
<Directory />
AllowOverride None
Require all denied
</Directory>
# Direcrory and files to be served
DirectoryIndex index.html
DocumentRoot "${GITPOD_REPO_ROOT}/www"
<Directory "${GITPOD_REPO_ROOT}/www">
Require all granted
</Directory>
# Include conf installed via apt-get
IncludeOptional /etc/apache2/conf-enabled/*.conf
# https://github.com/gitpod-io/apache-example/blob/master/apache/apache.conf
`;

<template>
<CodeBlock @code={{codeExample}} @language="apache" />
</template>
27 changes: 27 additions & 0 deletions test-app/app/components/language-tests/apex.gts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { CodeBlock } from 'ember-shiki';

const codeExample = `
public class EmailManager {
public static void sendMail(String address, String subject, String body) {
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {address};
mail.setToAddresses(toAddresses);
mail.setSubject(subject);
mail.setPlainTextBody(body);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
String address = 'YOUR_EMAIL_ADDRESS';
String subject = 'Speaker Confirmation';
String body = 'Thank you for speaking at the conference.';
EmailManager.sendMail(address, subject, body);
// From http://ccoenraets.github.io/salesforce-developer-workshop/Creating-an-Apex-Class.html
`;

<template>
<CodeBlock @code={{codeExample}} @language="apex" />
</template>
45 changes: 45 additions & 0 deletions test-app/app/components/language-tests/apl.gts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { CodeBlock } from 'ember-shiki';

const codeExample = `
CND ← {
X ← ⍵
a ← 0.31938153 ¯0.356563782 1.781477937 ¯1.821255978 1.330274429
l ← |X
k ← ÷1+0.2316419×l
w ← 1 - (÷((2×(○1))*0.5)) × (*-(l×l)÷2) × (a +.× (k*⍳5))
((|0⌊×X)×(1-w))+(1-|0⌊×X)×w
}
⍝ S - current price
⍝ X - strike price
⍝ T - expiry in years
⍝ r - riskless interest rate
⍝ v - volatility
S ← 60
X ← 65
T ← 1
r ← 0.1
v ← 0.2
d1 ← { ((⍟S÷X)+(r+(v*2)÷2)×⍵)÷(v×⍵*0.5) }
d2 ← { (d1 ⍵) -v×⍵*0.5 }
⍝ Call price
callPrice ← { (S×CND(d1 ⍵))-(X×*-r×⍵)×CND(d2 ⍵) }
avg ← { (+/⍵) ÷ ⊃⍴ ⍵ }
⎕←avg callPrice¨ (⍳ 100000) ÷ 10000
⍝ Put price (not tested)
⍝ putPrice ← { (X×*-r×⍵)×CND(-d2 ⍵)-S×CND(-d1 ⍵) }
⍝ From https://github.com/melsman/apltail/blob/master/tests/blacksch.apl
`;

<template>
<CodeBlock @code={{codeExample}} @language="apl" />
</template>
26 changes: 26 additions & 0 deletions test-app/app/components/language-tests/applescript.gts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { CodeBlock } from 'ember-shiki';

const codeExample = `
tell application "Address Book"
set bDayList to name of every person whose birth date is not missing value
choose from list bDayList with prompt "Whose birthday would you like?"
if the result is not false then
set aName to item 1 of the result
set theBirthday to birth date of person named aName
display dialog aName & "'s birthday is " & date string of theBirthday
end if
end tell
-- From https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_cmds.html`;
<template>
<CodeBlock @code={{codeExample}} @language="applescript" />
</template>
37 changes: 37 additions & 0 deletions test-app/app/components/language-tests/ara.gts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { CodeBlock } from 'ember-shiki';

const codeExample = `
namespace MyNamespace;
use MyOtherNamespace\MyOtherClass;
use function MyOtherNamespace\my_other_function;
use const MyOtherNamespace\MY_OTHER_CONST;
const MY_CONST = 1;
type MyType = int;
interface MyInterface {
// ...
}
class MyClass {
// ...
}
enum MyEnum {
// ...
}
function my_function(): void {
// ...
}
https://ara-lang.io/fundamentals/structure.html
`;

<template>
<CodeBlock @code={{codeExample}} @language="ara" />
</template>
25 changes: 25 additions & 0 deletions test-app/app/components/language-tests/asm.gts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { CodeBlock } from 'ember-shiki';

const codeExample = `
segment .text ;code segment
global_start ;must be declared for linker
_start: ;tell linker entry point
mov edx,len ;message length
mov ecx,msg ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
segment .data ;data segment
msg db 'Hello, world!',0xa ;our dear string
len equ $ - msg ;length of our dear string
;From https://www.tutorialspoint.com/assembly_programming/assembly_memory_segments.htm`;

<template>
<CodeBlock @code={{codeExample}} @language="asm" />
</template>
36 changes: 36 additions & 0 deletions test-app/app/components/language-tests/astro.gts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { CodeBlock } from 'ember-shiki';

const codeExample = `
---
// Your component script here!
import Banner from '../components/Banner.astro';
import ReactPokemonComponent from '../components/ReactPokemonComponent.jsx';
const myFavoritePokemon = [/* ... */];
const { title } = Astro.props;
---
<!-- HTML comments supported! -->
{/* JS comment syntax is also valid! */}
<Banner />
<h1>Hello, world!</h1>
<!-- Use props and other variables from the component script: -->
<p>{title}</p>
<!-- Include other UI framework components with a \`client:\` directive to hydrate: -->
<ReactPokemonComponent client:visible />
<!-- Mix HTML with JavaScript expressions, similar to JSX: -->
<ul>
{myFavoritePokemon.map((data) => <li>{data.name}</li>)}
</ul>
<!-- Use a template directive to build class names from multiple strings or even objects! -->
<p class:list={["add", "dynamic", {classNames: true}]} />
<!-- From https://docs.astro.build/en/core-concepts/astro-components/ -->
`;

<template>
<CodeBlock @code={{codeExample}} @language="astro" />
</template>
32 changes: 32 additions & 0 deletions test-app/app/components/language-tests/awk.gts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { CodeBlock } from 'ember-shiki';

const codeExample = `
#!/bin/awk -f
BEGIN {
# How many lines
lines=0;
total=0;
}
{
# this code is executed once for each line
# increase the number of files
lines++;
# increase the total size, which is field #1
total+=$1;
}
END {
# end, now output the total
print lines " lines read";
print "total is ", total;
if (lines > 0 ) {
print "average is ", total/lines;
} else {
print "average is 0";
}
}
#From https://www.grymoire.com/Unix/Awk.html`;
<template>
<CodeBlock @code={{codeExample}} @language="awk" />
</template>
Loading

0 comments on commit 07cb26b

Please sign in to comment.