1
0
mirror of git://f0xx.org/android_cast synced 2026-07-29 06:39:09 +03:00

header update

This commit is contained in:
Anton Afanasyeu
2026-05-20 17:24:50 +02:00
parent 5d8e82d2e6
commit ee4947a348
241 changed files with 1214 additions and 783 deletions

View File

@@ -8,12 +8,15 @@ from pathlib import Path
from header_lib import (
apply_header_to_content,
compute_digest,
format_identity,
has_valid_header,
is_excluded_path,
parse_identity,
render_header,
resolve_header_contributor,
strip_existing_header,
build_meta,
)
from pathlib import Path
import header_lib
@@ -39,15 +42,41 @@ public class Foo {
self.assertIn("public class Foo", body)
self.assertNotIn("package com.example", body.split("public class")[0])
def test_strip_php_opener(self) -> None:
def test_php_header_wrapped_in_comment(self) -> None:
src = "<?php\ndeclare(strict_types=1);\n"
with tempfile.TemporaryDirectory() as tmp:
path = Path(tmp) / "bootstrap.php"
path.write_text(src, encoding="utf-8")
out = apply_header_to_content(path, src)
self.assertTrue(out.startswith("<?php\n"))
self.assertIn("/* package bootstrap.php */", out)
self.assertTrue(out.startswith("<?php\n/*\n"))
self.assertIn("*/\ndeclare(strict_types=1)", out)
self.assertNotIn("?>\n<?php", out)
self.assertNotIn("/*********************************************************************", out)
body, _ = strip_existing_header(out, ".php")
self.assertTrue(body.startswith("declare(strict_types=1)"))
def test_php_html_template(self) -> None:
src = "<!DOCTYPE html>\n<html></html>\n"
with tempfile.TemporaryDirectory() as tmp:
path = Path(tmp) / "page.php"
path.write_text(src, encoding="utf-8")
out = apply_header_to_content(path, src)
self.assertIn("?>\n<!DOCTYPE", out)
self.assertNotIn("<?php\n<!DOCTYPE", out)
def test_commit_excluded_from_digest(self) -> None:
with tempfile.TemporaryDirectory() as tmp:
path = Path(tmp) / "X.java"
path.write_text("package p;\npublic class X {}\n", encoding="utf-8")
body, _ = strip_existing_header(
apply_header_to_content(path, path.read_text()), ".java")
meta = build_meta(path, body, path.read_text())
meta.commit_sha = "aaa"
d1 = compute_digest(render_header(meta, None, ".java", for_digest=True), body)
meta.commit_sha = "bbb"
d2 = compute_digest(render_header(meta, None, ".java", for_digest=True), body)
self.assertEqual(d1, d2)
def test_format_identity(self) -> None:
self.assertEqual("Ada <a@b.c>", format_identity("Ada", "a@b.c"))