const {
	compressText,
	decompressText,
	calculateCompressionRatio,
	estimateTokens,
	getCompressionInfo,
} = require("./synthlang_native");

console.log("=== SynthLang Native Rust Module Test ===\n");

// Show module info
const info = getCompressionInfo();
console.log("Module Info:", info);

// Test compression
const testTexts = [
	"function calculateTotal(items, taxRate, discountCode) { let subtotal = 0; for (const item of items) { subtotal += item.price * item.quantity; } }",
	"The quick brown fox jumps over the lazy dog and then runs away with the chicken",
	"import { Component } from 'react'; export default class MyComponent extends Component { render() { return <div>Hello</div>; } }",
	"async function fetchData() { const response = await fetch('/api/data'); const data = await response.json(); return data; }",
];

for (const text of testTexts) {
	console.log("\n---");
	console.log(
		"Original:",
		text.substring(0, 80) + (text.length > 80 ? "..." : ""),
	);
	console.log("Length:", text.length, "chars");

	const compressed = compressText(text);
	console.log(
		"Compressed:",
		compressed.substring(0, 80) + (compressed.length > 80 ? "..." : ""),
	);
	console.log("Compressed Length:", compressed.length, "chars");

	const ratio = calculateCompressionRatio(text, compressed);
	console.log("Compression Ratio:", (ratio * 100).toFixed(1) + "%");

	const origTokens = estimateTokens(text);
	const compTokens = estimateTokens(compressed);
	console.log(
		"Tokens:",
		origTokens,
		"→",
		compTokens,
		"(saved:",
		origTokens - compTokens,
		")",
	);

	const decompressed = decompressText(compressed);
	console.log(
		"Decompressed:",
		decompressed.substring(0, 80) + (decompressed.length > 80 ? "..." : ""),
	);
	console.log(
		"Roundtrip OK:",
		decompressed === text ? "✅" : "❌ (lossy as expected)",
	);
}

console.log("\n=== Done ===");
