update: test for with, extends, super, include and commment
This commit is contained in:
parent
745b2b29ca
commit
36cc1caac0
1 changed files with 164 additions and 163 deletions
|
|
@ -68,7 +68,6 @@ test "renderer: filtros + autoescape" {
|
||||||
\\Filtrado: maiusculo-e-slug
|
\\Filtrado: maiusculo-e-slug
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
// std.debug.print("OUTPUT:\n\n{s}\n", .{buf.items});
|
// std.debug.print("OUTPUT:\n\n{s}\n", .{buf.items});
|
||||||
|
|
||||||
try testing.expectEqualStrings(expected, buf.items);
|
try testing.expectEqualStrings(expected, buf.items);
|
||||||
|
|
@ -432,121 +431,123 @@ test "renderer - comment" {
|
||||||
try testing.expectEqualStrings(expected, output);
|
try testing.expectEqualStrings(expected, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
// test "renderer - full template with extends, super, include, comment" {
|
test "renderer - full template with extends, super, include, comment" {
|
||||||
// std.debug.print("____________________________________________________\n", .{});
|
std.debug.print("____________________________________________________\n", .{});
|
||||||
// std.debug.print("\n11 - renderer - full template with extends, super, include, comment\n\n", .{});
|
std.debug.print("11 - renderer - full template with extends, super, include, comment\n", .{});
|
||||||
// const alloc = testing.allocator;
|
const alloc = testing.allocator;
|
||||||
//
|
|
||||||
// const header = "<header>Bem-vindo</header>";
|
const header = "<header>Bem-vindo</header>";
|
||||||
// const base =
|
const base =
|
||||||
// \\{% include "header.html" %}
|
\\{% include "header.html" %}
|
||||||
// \\<main>
|
\\<main>
|
||||||
// \\ {% block content %}
|
\\ {% block content %}
|
||||||
// \\ Conteúdo padrão
|
\\ Conteúdo padrão
|
||||||
// \\ {% endblock %}
|
\\ {% endblock %}
|
||||||
// \\</main>
|
\\</main>
|
||||||
// ;
|
;
|
||||||
//
|
|
||||||
// const child =
|
const child =
|
||||||
// \\{% extends "base.html" %}
|
\\{% extends "base.html" %}
|
||||||
// \\{% block content %}
|
\\{% block content %}
|
||||||
// \\ {{ block.super }}
|
\\ {{ block.super }}
|
||||||
// \\ Conteúdo do filho
|
\\ Conteúdo do filho
|
||||||
// \\ {% comment %} Isso não aparece {% endcomment %}
|
\\ {% comment %} Isso não aparece {% endcomment %}
|
||||||
// \\{% endblock %}
|
\\{% endblock %}
|
||||||
// \\{% comment %} bazinga {% endcomment %}
|
\\{% comment %} bazinga {% endcomment %}
|
||||||
// ;
|
;
|
||||||
//
|
|
||||||
// try std.fs.cwd().writeFile(.{ .sub_path = "header.html", .data = header });
|
try std.fs.cwd().writeFile(.{ .sub_path = "header.html", .data = header });
|
||||||
// try std.fs.cwd().writeFile(.{ .sub_path = "base.html", .data = base });
|
try std.fs.cwd().writeFile(.{ .sub_path = "base.html", .data = base });
|
||||||
// try std.fs.cwd().writeFile(.{ .sub_path = "child.html", .data = child });
|
try std.fs.cwd().writeFile(.{ .sub_path = "child.html", .data = child });
|
||||||
// defer std.fs.cwd().deleteFile("header.html") catch {};
|
defer std.fs.cwd().deleteFile("header.html") catch {};
|
||||||
// defer std.fs.cwd().deleteFile("base.html") catch {};
|
defer std.fs.cwd().deleteFile("base.html") catch {};
|
||||||
// defer std.fs.cwd().deleteFile("child.html") catch {};
|
defer std.fs.cwd().deleteFile("child.html") catch {};
|
||||||
//
|
|
||||||
// var ctx = Context.init(alloc);
|
var ctx = Context.init(alloc);
|
||||||
// defer ctx.deinit();
|
defer ctx.deinit();
|
||||||
//
|
|
||||||
// var cache = TemplateCache.init(alloc);
|
var cache = TemplateCache.init(alloc);
|
||||||
// defer cache.deinit();
|
defer cache.deinit();
|
||||||
// cache.default_path = ".";
|
cache.default_path = ".";
|
||||||
//
|
|
||||||
// const renderer = Renderer.init(&ctx, &cache);
|
const renderer = Renderer.init(&ctx, &cache);
|
||||||
//
|
|
||||||
// var buf = std.ArrayList(u8){};
|
var buf = std.ArrayList(u8){};
|
||||||
// defer buf.deinit(alloc);
|
defer buf.deinit(alloc);
|
||||||
//
|
|
||||||
// try renderer.render("child.html", buf.writer(alloc));
|
try renderer.render("child.html", buf.writer(alloc));
|
||||||
//
|
|
||||||
// const output = buf.items;
|
const output = buf.items;
|
||||||
// // std.debug.print("OUTPUT:\n\n{s}\n", .{output});
|
// std.debug.print("OUTPUT:\n\n{s}\n", .{output});
|
||||||
//
|
|
||||||
// try testing.expect(std.mem.indexOf(u8, output, "<header>Bem-vindo</header>") != null);
|
try testing.expect(std.mem.indexOf(u8, output, "<header>Bem-vindo</header>") != null);
|
||||||
// try testing.expect(std.mem.indexOf(u8, output, "Conteúdo padrão") != null);
|
try testing.expect(std.mem.indexOf(u8, output, "<main>") != null);
|
||||||
// try testing.expect(std.mem.indexOf(u8, output, "Conteúdo do filho") != null);
|
try testing.expect(std.mem.indexOf(u8, output, "Conteúdo padrão") != null);
|
||||||
// try testing.expect(std.mem.indexOf(u8, output, "Isso não aparece") == null);
|
try testing.expect(std.mem.indexOf(u8, output, "Conteúdo do filho") != null);
|
||||||
// }
|
try testing.expect(std.mem.indexOf(u8, output, "Isso não aparece") == null);
|
||||||
//
|
try testing.expect(std.mem.indexOf(u8, output, "bazinga") == null);
|
||||||
// test "renderer - if inside block" {
|
}
|
||||||
// std.debug.print("____________________________________________________\n", .{});
|
|
||||||
// std.debug.print("\n12 - render - if inside block\n\n", .{});
|
test "renderer - if inside block" {
|
||||||
// const alloc = testing.allocator;
|
std.debug.print("____________________________________________________\n", .{});
|
||||||
//
|
std.debug.print("12 - render - if inside block\n", .{});
|
||||||
// const base =
|
const alloc = testing.allocator;
|
||||||
// \\<main>
|
|
||||||
// \\ {% block content %}
|
const base =
|
||||||
// \\ Conteúdo padrão
|
\\<main>
|
||||||
// \\ {% endblock %}
|
\\ {% block content %}
|
||||||
// \\</main>
|
\\ Conteúdo padrão
|
||||||
// ;
|
\\ {% endblock %}
|
||||||
//
|
\\</main>
|
||||||
// const child =
|
;
|
||||||
// \\{% extends "base.html" %}
|
|
||||||
// \\{% block content %}
|
const child =
|
||||||
// \\ {{ block.super }}
|
\\{% extends "base.html" %}
|
||||||
// \\ Conteúdo do filho
|
\\{% block content %}
|
||||||
// \\{% if idade > 18 %}
|
\\ {{ block.super }}
|
||||||
// \\ Idade: {{ idade }}
|
\\ Conteúdo do filho
|
||||||
// \\{% else %}
|
\\{% if idade > 18 %}
|
||||||
// \\ Oops
|
\\ Idade: {{ idade }}
|
||||||
// \\{% endif %}
|
\\{% else %}
|
||||||
// \\{% endblock %}
|
\\ Oops
|
||||||
// ;
|
\\{% endif %}
|
||||||
//
|
\\{% endblock %}
|
||||||
// try std.fs.cwd().writeFile(.{ .sub_path = "base.html", .data = base });
|
;
|
||||||
// try std.fs.cwd().writeFile(.{ .sub_path = "child.html", .data = child });
|
|
||||||
// defer std.fs.cwd().deleteFile("base.html") catch {};
|
try std.fs.cwd().writeFile(.{ .sub_path = "base.html", .data = base });
|
||||||
// defer std.fs.cwd().deleteFile("child.html") catch {};
|
try std.fs.cwd().writeFile(.{ .sub_path = "child.html", .data = child });
|
||||||
//
|
defer std.fs.cwd().deleteFile("base.html") catch {};
|
||||||
// var ctx = Context.init(alloc);
|
defer std.fs.cwd().deleteFile("child.html") catch {};
|
||||||
// defer ctx.deinit();
|
|
||||||
//
|
var ctx = Context.init(alloc);
|
||||||
// var cache = TemplateCache.init(alloc);
|
defer ctx.deinit();
|
||||||
// defer cache.deinit();
|
|
||||||
// cache.default_path = ".";
|
var cache = TemplateCache.init(alloc);
|
||||||
//
|
defer cache.deinit();
|
||||||
// const renderer = Renderer.init(&ctx, &cache);
|
cache.default_path = ".";
|
||||||
//
|
|
||||||
// try ctx.set("idade", 23);
|
const renderer = Renderer.init(&ctx, &cache);
|
||||||
//
|
|
||||||
// var buf = std.ArrayList(u8){};
|
try ctx.set("idade", 23);
|
||||||
// defer buf.deinit(alloc);
|
|
||||||
//
|
var buf = std.ArrayList(u8){};
|
||||||
// try renderer.render("child.html", buf.writer(alloc));
|
defer buf.deinit(alloc);
|
||||||
//
|
|
||||||
// const output = buf.items;
|
try renderer.render("child.html", buf.writer(alloc));
|
||||||
//
|
|
||||||
// // std.debug.print("OUTPUT:\n\n{s}\n", .{output});
|
const output = buf.items;
|
||||||
//
|
|
||||||
// try testing.expect(std.mem.indexOf(u8, output, "Conteúdo padrão") != null);
|
// std.debug.print("OUTPUT:\n\n{s}\n", .{output});
|
||||||
// try testing.expect(std.mem.indexOf(u8, output, "Conteúdo do filho") != null);
|
|
||||||
// try testing.expect(std.mem.indexOf(u8, output, "Oops") == null);
|
try testing.expect(std.mem.indexOf(u8, output, "Conteúdo padrão") != null);
|
||||||
// }
|
try testing.expect(std.mem.indexOf(u8, output, "Conteúdo do filho") != null);
|
||||||
//
|
try testing.expect(std.mem.indexOf(u8, output, "Oops") == null);
|
||||||
|
try testing.expect(std.mem.indexOf(u8, output, "Idade: 23") != null);
|
||||||
|
}
|
||||||
|
|
||||||
test "renderer - if with operators" {
|
test "renderer - if with operators" {
|
||||||
std.debug.print("____________________________________________________\n", .{});
|
std.debug.print("____________________________________________________\n", .{});
|
||||||
std.debug.print("\n13 - render - if inside block\n\n", .{});
|
std.debug.print("13 - render - if inside block\n", .{});
|
||||||
|
|
||||||
const alloc = testing.allocator;
|
const alloc = testing.allocator;
|
||||||
var ctx = Context.init(alloc);
|
var ctx = Context.init(alloc);
|
||||||
|
|
@ -584,53 +585,53 @@ test "renderer - if with operators" {
|
||||||
try testing.expect(std.mem.indexOf(u8, buf.items, "Low Order") != null);
|
try testing.expect(std.mem.indexOf(u8, buf.items, "Low Order") != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// test "renderer - widthratio inside block" {
|
test "renderer - widthratio inside block" {
|
||||||
// std.debug.print("____________________________________________________\n", .{});
|
std.debug.print("____________________________________________________\n", .{});
|
||||||
// std.debug.print("\n14 - render - widthratio inside block\n\n", .{});
|
std.debug.print("14 - render - widthratio inside block\n", .{});
|
||||||
// const alloc = testing.allocator;
|
const alloc = testing.allocator;
|
||||||
//
|
|
||||||
// const base =
|
const base =
|
||||||
// \\<main>
|
\\<main>
|
||||||
// \\ {% block content %}
|
\\ {% block content %}
|
||||||
// \\ Conteúdo padrão
|
\\ Conteúdo padrão
|
||||||
// \\ {% endblock %}
|
\\ {% endblock %}
|
||||||
// \\</main>
|
\\</main>
|
||||||
// ;
|
;
|
||||||
//
|
|
||||||
// const child =
|
const child =
|
||||||
// \\{% extends "base.html" %}
|
\\{% extends "base.html" %}
|
||||||
// \\{% block content %}
|
\\{% block content %}
|
||||||
// \\ Conteúdo do filho
|
\\ Conteúdo do filho
|
||||||
// \\<img src="bar.png" alt="Bar" height="10" width="{% widthratio value 400 %}">
|
\\<img src="bar.png" alt="Bar" height="10" width="{% widthratio value 400 %}">
|
||||||
// \\ {{ block.super }}
|
\\ {{ block.super }}
|
||||||
// \\{% endblock %}
|
\\{% endblock %}
|
||||||
// ;
|
;
|
||||||
//
|
|
||||||
// try std.fs.cwd().writeFile(.{ .sub_path = "base.html", .data = base });
|
try std.fs.cwd().writeFile(.{ .sub_path = "base.html", .data = base });
|
||||||
// try std.fs.cwd().writeFile(.{ .sub_path = "child.html", .data = child });
|
try std.fs.cwd().writeFile(.{ .sub_path = "child.html", .data = child });
|
||||||
// defer std.fs.cwd().deleteFile("base.html") catch {};
|
defer std.fs.cwd().deleteFile("base.html") catch {};
|
||||||
// defer std.fs.cwd().deleteFile("child.html") catch {};
|
defer std.fs.cwd().deleteFile("child.html") catch {};
|
||||||
//
|
|
||||||
// var ctx = Context.init(alloc);
|
var ctx = Context.init(alloc);
|
||||||
// defer ctx.deinit();
|
defer ctx.deinit();
|
||||||
//
|
|
||||||
// var cache = TemplateCache.init(alloc);
|
var cache = TemplateCache.init(alloc);
|
||||||
// defer cache.deinit();
|
defer cache.deinit();
|
||||||
// cache.default_path = ".";
|
cache.default_path = ".";
|
||||||
//
|
|
||||||
// const renderer = Renderer.init(&ctx, &cache);
|
const renderer = Renderer.init(&ctx, &cache);
|
||||||
//
|
|
||||||
// try ctx.set("value", 50);
|
try ctx.set("value", 50);
|
||||||
//
|
|
||||||
// var buf = std.ArrayList(u8){};
|
var buf = std.ArrayList(u8){};
|
||||||
// defer buf.deinit(alloc);
|
defer buf.deinit(alloc);
|
||||||
//
|
|
||||||
// try renderer.render("child.html", buf.writer(alloc));
|
try renderer.render("child.html", buf.writer(alloc));
|
||||||
//
|
|
||||||
// const output = buf.items;
|
const output = buf.items;
|
||||||
//
|
|
||||||
// // std.debug.print("OUTPUT:\n\n{s}\n", .{output});
|
// std.debug.print("OUTPUT:\n\n{s}\n", .{output});
|
||||||
//
|
|
||||||
// try testing.expect(std.mem.indexOf(u8, output, "Conteúdo padrão") != null);
|
try testing.expect(std.mem.indexOf(u8, output, "Conteúdo padrão") != null);
|
||||||
// try testing.expect(std.mem.indexOf(u8, output, "Conteúdo do filho") != null);
|
try testing.expect(std.mem.indexOf(u8, output, "Conteúdo do filho") != null);
|
||||||
// }
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue