un-inception/clients/php/sync/tests/LanguageDetectionTest.php
russell@unturf.com 331cba42aa feat: Complete 6 additional SDK implementations with fixes and examples
Go Async SDK (clients/go/async/):
- Fixed case-sensitive language detection bug (.R for R language)
- Created go.mod for module management
- Added comprehensive test suite
- Created 3 examples with expected output comments
- Added README with full documentation

Java Sync SDK (clients/java/sync/):
- RENAMED: Unsandbox.java -> Un.java (matches naming convention)
- Updated class name from Unsandbox to Un
- Created pom.xml for Maven build
- Added 6 examples (simple + SDK client versions)
- Created test suite with JUnit 5
- Added README with API documentation

JavaScript Async SDK (clients/javascript/async/):
- Fixed unused import
- Created package.json with ES module support
- Added 5 examples covering all async patterns
- Created 71 tests (all passing)
- Added comprehensive README

PHP Sync SDK (clients/php/sync/):
- RENAMED: Unsandbox.php -> un.php (matches naming convention)
- Created composer.json with PSR-4 autoloading
- Created phpunit.xml for testing
- Added 4 examples with expected output comments
- Created 54 tests across 4 test files
- Added README with full documentation

Ruby Sync SDK (clients/ruby/sync/):
- Created Gemfile and un.gemspec
- Created Rakefile with test task
- Updated examples to actually use the SDK
- Added 4 examples (hello_world, async_job, language_detection, snapshots)
- Created comprehensive test suite with 30+ tests
- Added README with documentation

Rust Sync SDK (clients/rust/sync/):
- Updated Cargo.toml with example declarations
- Created 4 examples (hello_world, fibonacci, multi_language, async_polling)
- Added comprehensive README with API reference
- All dependencies verified correct

All SDKs verified:
- HMAC-SHA256 authentication implemented
- 4-tier credential system (args > env > ~/.unsandbox > ./accounts.csv)
- Expected output comments for pipeline validation
- Proper error handling
- Language detection support
2026-01-15 17:32:24 -05:00

210 lines
6 KiB
PHP

<?php
/**
* Tests for language detection from filename extension
*/
declare(strict_types=1);
namespace Unsandbox\Tests;
use PHPUnit\Framework\TestCase;
require_once __DIR__ . '/../src/un.php';
use Unsandbox\Unsandbox;
class LanguageDetectionTest extends TestCase
{
public function testDetectPython(): void
{
$this->assertEquals('python', Unsandbox::detectLanguage('script.py'));
$this->assertEquals('python', Unsandbox::detectLanguage('test.py'));
}
public function testDetectJavaScript(): void
{
$this->assertEquals('javascript', Unsandbox::detectLanguage('app.js'));
$this->assertEquals('javascript', Unsandbox::detectLanguage('index.js'));
}
public function testDetectTypeScript(): void
{
$this->assertEquals('typescript', Unsandbox::detectLanguage('main.ts'));
}
public function testDetectRuby(): void
{
$this->assertEquals('ruby', Unsandbox::detectLanguage('script.rb'));
}
public function testDetectPhp(): void
{
$this->assertEquals('php', Unsandbox::detectLanguage('index.php'));
}
public function testDetectGo(): void
{
$this->assertEquals('go', Unsandbox::detectLanguage('main.go'));
}
public function testDetectRust(): void
{
$this->assertEquals('rust', Unsandbox::detectLanguage('main.rs'));
}
public function testDetectC(): void
{
$this->assertEquals('c', Unsandbox::detectLanguage('program.c'));
}
public function testDetectCpp(): void
{
$this->assertEquals('cpp', Unsandbox::detectLanguage('program.cpp'));
$this->assertEquals('cpp', Unsandbox::detectLanguage('code.cc'));
$this->assertEquals('cpp', Unsandbox::detectLanguage('main.cxx'));
}
public function testDetectJava(): void
{
$this->assertEquals('java', Unsandbox::detectLanguage('Main.java'));
}
public function testDetectKotlin(): void
{
$this->assertEquals('kotlin', Unsandbox::detectLanguage('main.kt'));
}
public function testDetectCSharp(): void
{
$this->assertEquals('csharp', Unsandbox::detectLanguage('Program.cs'));
}
public function testDetectHaskell(): void
{
$this->assertEquals('haskell', Unsandbox::detectLanguage('Main.hs'));
}
public function testDetectElixir(): void
{
$this->assertEquals('elixir', Unsandbox::detectLanguage('script.ex'));
$this->assertEquals('elixir', Unsandbox::detectLanguage('script.exs'));
}
public function testDetectBash(): void
{
$this->assertEquals('bash', Unsandbox::detectLanguage('script.sh'));
}
public function testDetectLua(): void
{
$this->assertEquals('lua', Unsandbox::detectLanguage('script.lua'));
}
public function testDetectPerl(): void
{
$this->assertEquals('perl', Unsandbox::detectLanguage('script.pl'));
}
public function testDetectR(): void
{
$this->assertEquals('r', Unsandbox::detectLanguage('analysis.r'));
$this->assertEquals('r', Unsandbox::detectLanguage('analysis.R'));
}
public function testDetectScheme(): void
{
$this->assertEquals('scheme', Unsandbox::detectLanguage('code.scm'));
$this->assertEquals('scheme', Unsandbox::detectLanguage('code.ss'));
}
public function testDetectNullForEmptyFilename(): void
{
$this->assertNull(Unsandbox::detectLanguage(''));
}
public function testDetectNullForNoExtension(): void
{
$this->assertNull(Unsandbox::detectLanguage('Makefile'));
$this->assertNull(Unsandbox::detectLanguage('README'));
}
public function testDetectNullForUnknownExtension(): void
{
$this->assertNull(Unsandbox::detectLanguage('file.xyz'));
$this->assertNull(Unsandbox::detectLanguage('file.unknown'));
}
public function testDetectWithPath(): void
{
$this->assertEquals('python', Unsandbox::detectLanguage('/path/to/script.py'));
$this->assertEquals('javascript', Unsandbox::detectLanguage('./src/app.js'));
}
public function testDetectWithMultipleDots(): void
{
$this->assertEquals('python', Unsandbox::detectLanguage('my.script.test.py'));
$this->assertEquals('javascript', Unsandbox::detectLanguage('app.min.js'));
}
public function testAllSupportedLanguages(): void
{
$expected = [
'py' => 'python',
'js' => 'javascript',
'ts' => 'typescript',
'rb' => 'ruby',
'php' => 'php',
'pl' => 'perl',
'sh' => 'bash',
'r' => 'r',
'lua' => 'lua',
'go' => 'go',
'rs' => 'rust',
'c' => 'c',
'cpp' => 'cpp',
'cc' => 'cpp',
'cxx' => 'cpp',
'java' => 'java',
'kt' => 'kotlin',
'm' => 'objc',
'cs' => 'csharp',
'fs' => 'fsharp',
'hs' => 'haskell',
'ml' => 'ocaml',
'clj' => 'clojure',
'scm' => 'scheme',
'ss' => 'scheme',
'erl' => 'erlang',
'ex' => 'elixir',
'exs' => 'elixir',
'jl' => 'julia',
'd' => 'd',
'nim' => 'nim',
'zig' => 'zig',
'v' => 'v',
'cr' => 'crystal',
'dart' => 'dart',
'groovy' => 'groovy',
'f90' => 'fortran',
'f95' => 'fortran',
'lisp' => 'commonlisp',
'lsp' => 'commonlisp',
'cob' => 'cobol',
'tcl' => 'tcl',
'raku' => 'raku',
'pro' => 'prolog',
'p' => 'prolog',
'4th' => 'forth',
'forth' => 'forth',
'fth' => 'forth',
];
foreach ($expected as $ext => $language) {
$this->assertEquals(
$language,
Unsandbox::detectLanguage("test.{$ext}"),
"Extension .{$ext} should map to {$language}"
);
}
}
}