fortrangoingonforty/facsimile / f3b77a5

Browse files

scratch files for syntax testing

Authored by espadonne
SHA
f3b77a588469c99bf2020193e83628ea0958f1cc
Parents
206363c
Tree
1c956d3

7 changed files

StatusFile+-
A scratch/test.c 29 0
A scratch/test.go 54 0
A scratch/test.js 50 0
A scratch/test.rs 43 0
A scratch/test.sh 58 0
A scratch/test_syntax.f90 38 0
A scratch/test_syntax.py 23 0
scratch/test.cadded
@@ -0,0 +1,29 @@
1
+#include <stdio.h>
2
+#include <stdlib.h>
3
+
4
+// Function to calculate factorial
5
+int factorial(int n) {
6
+    if (n <= 1) {
7
+        return 1;
8
+    }
9
+    return n * factorial(n - 1);
10
+}
11
+
12
+int main(int argc, char *argv[]) {
13
+    /* Multi-line comment
14
+       Testing syntax highlighting */
15
+    int num = 10;
16
+    float pi = 3.14159;
17
+    char message[] = "Hello, C!";
18
+
19
+    printf("%s\n", message);
20
+    printf("Factorial of %d is %d\n", num, factorial(num));
21
+
22
+    for (int i = 0; i < 5; i++) {
23
+        if (i % 2 == 0) {
24
+            printf("%d is even\n", i);
25
+        }
26
+    }
27
+
28
+    return 0;
29
+}
scratch/test.goadded
@@ -0,0 +1,54 @@
1
+package main
2
+
3
+import (
4
+    "fmt"
5
+    "strings"
6
+)
7
+
8
+// Person struct definition
9
+type Person struct {
10
+    Name string
11
+    Age  int
12
+}
13
+
14
+// Method on Person
15
+func (p Person) Greet() {
16
+    fmt.Printf("Hello, I'm %s and I'm %d years old\n", p.Name, p.Age)
17
+}
18
+
19
+func fibonacci(n int) int {
20
+    if n <= 1 {
21
+        return n
22
+    }
23
+    return fibonacci(n-1) + fibonacci(n-2)
24
+}
25
+
26
+func main() {
27
+    // Variable declarations
28
+    var message string = "Hello, Go!"
29
+    count := 42
30
+    pi := 3.14159
31
+
32
+    fmt.Println(message)
33
+
34
+    // Create a person
35
+    person := Person{Name: "Bob", Age: 25}
36
+    person.Greet()
37
+
38
+    // Slice and loop
39
+    numbers := []int{1, 2, 3, 4, 5}
40
+    for i, num := range numbers {
41
+        if num%2 == 0 {
42
+            fmt.Printf("Index %d: %d is even\n", i, num)
43
+        }
44
+    }
45
+
46
+    // Channel example
47
+    ch := make(chan string)
48
+    go func() {
49
+        ch <- "Goroutine message"
50
+    }()
51
+
52
+    msg := <-ch
53
+    fmt.Println(msg)
54
+}
scratch/test.jsadded
@@ -0,0 +1,50 @@
1
+// Modern JavaScript example
2
+class Calculator {
3
+    constructor() {
4
+        this.result = 0;
5
+    }
6
+
7
+    add(a, b) {
8
+        this.result = a + b;
9
+        return this.result;
10
+    }
11
+
12
+    multiply(a, b) {
13
+        return a * b;
14
+    }
15
+}
16
+
17
+// Arrow function
18
+const fibonacci = (n) => {
19
+    if (n <= 1) return n;
20
+    return fibonacci(n - 1) + fibonacci(n - 2);
21
+};
22
+
23
+// Async/await example
24
+async function fetchData(url) {
25
+    try {
26
+        const response = await fetch(url);
27
+        const data = await response.json();
28
+        return data;
29
+    } catch (error) {
30
+        console.error("Error:", error);
31
+    }
32
+}
33
+
34
+// Main execution
35
+const calc = new Calculator();
36
+console.log(`5 + 3 = ${calc.add(5, 3)}`);
37
+
38
+// Array methods
39
+const numbers = [1, 2, 3, 4, 5];
40
+const doubled = numbers.map(x => x * 2);
41
+const evens = numbers.filter(x => x % 2 === 0);
42
+
43
+// Object destructuring
44
+const { result } = calc;
45
+console.log("Result:", result);
46
+
47
+// Template literals and promises
48
+Promise.resolve("Hello")
49
+    .then(msg => `${msg}, World!`)
50
+    .then(console.log);
scratch/test.rsadded
@@ -0,0 +1,43 @@
1
+use std::collections::HashMap;
2
+
3
+// A simple struct
4
+#[derive(Debug)]
5
+struct Person {
6
+    name: String,
7
+    age: u32,
8
+}
9
+
10
+impl Person {
11
+    fn new(name: &str, age: u32) -> Self {
12
+        Person {
13
+            name: name.to_string(),
14
+            age,
15
+        }
16
+    }
17
+
18
+    fn greet(&self) {
19
+        println!("Hello, I'm {} and I'm {} years old", self.name, self.age);
20
+    }
21
+}
22
+
23
+fn main() {
24
+    // Create a person
25
+    let person = Person::new("Alice", 30);
26
+    person.greet();
27
+
28
+    // Use a HashMap
29
+    let mut scores = HashMap::new();
30
+    scores.insert("Blue", 10);
31
+    scores.insert("Red", 50);
32
+
33
+    // Pattern matching
34
+    match scores.get("Blue") {
35
+        Some(score) => println!("Blue team score: {}", score),
36
+        None => println!("No score found"),
37
+    }
38
+
39
+    // Iterate with closure
40
+    let numbers = vec![1, 2, 3, 4, 5];
41
+    let doubled: Vec<i32> = numbers.iter().map(|x| x * 2).collect();
42
+    println!("Doubled: {:?}", doubled);
43
+}
scratch/test.shadded
@@ -0,0 +1,58 @@
1
+#!/bin/bash
2
+
3
+# Bash script example with syntax highlighting
4
+
5
+# Variables
6
+NAME="Bash Script"
7
+COUNT=10
8
+readonly CONSTANT="Can't change this"
9
+
10
+# Function definition
11
+function greet() {
12
+    local name=$1
13
+    echo "Hello, $name!"
14
+}
15
+
16
+# Conditional
17
+if [ -f "$0" ]; then
18
+    echo "This script exists: $0"
19
+fi
20
+
21
+# Case statement
22
+case "$1" in
23
+    start)
24
+        echo "Starting..."
25
+        ;;
26
+    stop)
27
+        echo "Stopping..."
28
+        ;;
29
+    *)
30
+        echo "Usage: $0 {start|stop}"
31
+        exit 1
32
+        ;;
33
+esac
34
+
35
+# Loops
36
+for i in {1..5}; do
37
+    if [ $((i % 2)) -eq 0 ]; then
38
+        echo "$i is even"
39
+    else
40
+        echo "$i is odd"
41
+    fi
42
+done
43
+
44
+# Array
45
+declare -a fruits=("apple" "banana" "orange")
46
+for fruit in "${fruits[@]}"; do
47
+    echo "Fruit: $fruit"
48
+done
49
+
50
+# Command substitution
51
+current_date=$(date +"%Y-%m-%d")
52
+echo "Today is: $current_date"
53
+
54
+# Pipe and redirection
55
+ls -la | grep "^d" > /tmp/directories.txt
56
+
57
+# Call function
58
+greet "World"
scratch/test_syntax.f90added
@@ -0,0 +1,38 @@
1
+program test_syntax
2
+    ! Test program for syntax highlighting
3
+    use iso_fortran_env, only: int32, real64
4
+    implicit none
5
+
6
+    integer :: i, n = 10
7
+    real(real64) :: pi = 3.14159265359
8
+    character(len=20) :: greeting = "Hello, Fortran!"
9
+
10
+    ! Print greeting
11
+    print *, greeting
12
+
13
+    ! Calculate factorial
14
+    print *, "Factorial of", n, "is", factorial(n)
15
+
16
+    ! Loop example
17
+    do i = 1, 5
18
+        if (mod(i, 2) == 0) then
19
+            print *, i, "is even"
20
+        else
21
+            print *, i, "is odd"
22
+        end if
23
+    end do
24
+
25
+contains
26
+
27
+    recursive function factorial(n) result(fact)
28
+        integer, intent(in) :: n
29
+        integer :: fact
30
+
31
+        if (n <= 1) then
32
+            fact = 1
33
+        else
34
+            fact = n * factorial(n - 1)
35
+        end if
36
+    end function factorial
37
+
38
+end program test_syntax
scratch/test_syntax.pyadded
@@ -0,0 +1,23 @@
1
+#!/usr/bin/env python
2
+"""Test file for syntax highlighting in fac"""
3
+
4
+def fibonacci(n: int) -> int:
5
+    """Calculate the nth Fibonacci number"""
6
+    if n <= 1:
7
+        return n
8
+    return fibonacci(n - 1) + fibonacci(n - 2)
9
+
10
+class Calculator:
11
+    def __init__(self):
12
+        self.result = 0
13
+
14
+    def add(self, x: float, y: float) -> float:
15
+        # Add two numbers
16
+        self.result = x + y
17
+        return self.result
18
+
19
+# Test the functions
20
+if __name__ == "__main__":
21
+    print("Fibonacci of 10:", fibonacci(10))
22
+    calc = Calculator()
23
+    print("5 + 3 =", calc.add(5, 3))